I was ashamed of my interprise code so much that I made my own bike. I'm less ashamed of him

image



This is a continuation of the text about the architecture of interprise systems. Reasoning is good, but what's the point without practical application. I'll show my framework in action.



It all started when I talked about the problems of designing applications in .NET and whined about the difficult life in a bloody enterprise. Then I described the solution I came up with and implemented myself - Reinforced.Tecture. It was theory, conceptual reasoning, visionary and whining again. This time it's about 2020, and HKT hasn't been delivered to C #.



Today I will demonstrate my approach in action using a simple project as an example and show the benefits that it gives: from reducing the amount of code to testing automation and an original approach to documentation. As old Torvalds advised: "Chatting is worthless, show me the code."



So, we need to do something simple, but working in Tecture. Since we are talking about an enterprise, I will choose an example that vaguely resembles a real business.



We need:



  • Simple essence. Products and orders immediately come to mind. Let there be products;
  • EF DbContext and local database;
  • Toy business logic;
  • A simple web project. All rank by rank, ASP.NET Core, WebAPI. We'll stick the logic into it.


Training



The project structure will be as follows:



image



I connected EF.Core to the assembly Data, put DbContext and glue code for migrations there. Because I want to leave the logic on .NET Standard and not drag EF with me.



By the way, interesting

DAL-, . — . , Tecture. .



We will look at Tecture behavior using an example of working with products. Here is its essence, and the logic around it will be simple and very stupid:



image



DbContext- , - . — . EF , . . EF — ORM-. EF-.



AcmeDbContext

image



MS SQL Express. — . EF.Core - — MySQL PostgreSQL. , , Tecture, . . .



, . Reinforced.Tecture Reinforced.Tecture.Aspects.Orm.



image



. , O/RM:



image



, Id. , . :



image





. Tecture end-user . web-. , Startup.cs, ConfigureServices. DI-, ASP.NET MVC. , AcmeDbContext:



image



Tecture EF. web-. 2 : O/RM DirectSQL. DirectSQL , . , - . , - , dll- . . — — :



image



Tecture . . . AcmeDbContext, LazyDisposable ( Lazy Disposable, ) . , EF . fluent-:



image



. " " . , , Tecture, , . separation of concerns: , , — — . , — , .



. , . , . , , , . — . , separation of concerns .



, : , , . glue-. , — , .



Tecture , . .



, ITecture . .





-, Id. , . DTO. , , :



image



, ITecture , , From<>. , Id DTO-:



image



, , . Id DTO- . C# . , DTO- :



image



image



:



image



image



IQueryable, All<>, . . — , . — AutoMapper, expression-. — . , . , . , . , .





, - . . , Tecture . . , :



image



, . . ORM- — :



image



image



, Id . ORM — . — , Id — . ? : Add IAddition<>. , IAddition<Product>. Key . Id. . IPrimaryKey<>. :



image



. - :



image



Postman Id .



-, Tecture. , , . — , .






. , .



. . 90% . , , — , .



, — . — . — .



.





. Tecture BeginTrace EndTrace. . :



image



Explain. Tecture . return :



image



! . , - . , , , — , , , . , , :



image



.Describe.



: - . , , , . — , .



, , . , . , . , .



Tecture : . . -, . , - , . , . , , . Knowledge management!



IDescriptive, , , . "User entity" "User Vasiliy Pupkin". , . , .



, - . Explain — , , . , : , .



.





. . web- : Reinforced.Tecture.Testing. — Roslyn. , . :



image



2 . GenerateData GenerateValidation. , :



image



: , C#-. , Tecture fake- . , , , -, Mockaroo. - — . , ?



. Reinforced.Tecture.Testing. , 4 :



image



: -, - ( + ). . !



, . - -. , .



, ...



Unit-



, . QA : ", , !". , , , unit-.



CI/CD — . , , , . . . , Tecture . : - , . — . .



— , , - . , , , . — — , .



. . .



— , GenerateData GenerateValidation. NuGet . , .



, :



image



image



, :



image



, unit- 5 . , .



, ( ). - unit-. , , , - .



.



-



. , . , .



, Tecture. , . , — , . .



— , DirectSql, . , . .



The packages have been published, the sources are there , I am in touch on twitter, telegram and on github. If you suddenly want to join the ranks of early adopters and take Tecture for your pet project - write to me, I will try to help.



Special thanks fillpackart, arttomand their We Are Doomed community for informational support and editing. Watch their podcast , it's awesome. There is even a release with me .



Good luck!




All Articles