The architecture of enterprise applications may be different

image



I am annoyed by the traditional architecture of business applications - I already talked about this. I criticize - I suggest. Now I will tell you where my search for solutions to the problems from the previous article led me.



I like to iterate over architectural concepts. All my life I have been trying to find something in the field of architecture and software design that works and at the same time is simple. It does not require a break in the brain for understanding and a radical paradigm shift. A lot of ideas have accumulated and I decided to combine the best of them in my framework - Reinforced.Tecture. Developing such things is a huge amount of food for thought, I want to share them.



Texts about such technical things are usually terribly boring. I honestly tried not to be boring, so my text turned out to be slightly aggressive. If you are interested in reading about the architecture of .NET applications with these rules, come on in.



Disclaimer

. , , .



: , , - . ( ), , β€” . . Tecture , . DevRel open source , . , , ( MIT-). , - β€” .



: . , , , . , . : , , , , , "-" . :



  • - Java (, C#) 80-90. β€” MS- eShopOnContainers, , - -. , peer review ;
  • . β€” , , .


"", "". β€” . , . , .NET.



: . , 100 UpWork- MVP. , , 30 15 . , , . , production-, -. node/react . , , . long term. " , " .



External systems



- : , β€” , - SalesForce. - , , , API . β€” -.



, β€” , . , , "-": , , . - β€” , .



: . , , . O/RM, SQL-. O/RM- . β€” INSERT- , . , , O/RM- : " ". , , . , . . β€” SaveChanges .



. , O/RM . , . β€” " " SQL, . , "object-relational impedance mismatch". . , : , . β€” , . , , . β€” . DBA - stored-.



. . : . , .



Tecture . , . , .



( )



, . , , . Tecture β€” , . β€” :



public interface Db { }


I .



CodeFest- - , , β€” " , HKT", . , .



C# type F# TypeScript, β€” interface . type β€” -, type inference . , C# HKT, reflection-.



( )



. . . . O/RM, SQL-. -, , , SQL . . , -.



"", "" β€” . , - . AOP . Tecture , , , ? , .



. C# . :



PM> Install-Package Reinforced.Tecture.Aspects.Orm
PM> Install-Package Reinforced.Tecture.Aspects.DirectSql


public interface Db :
        CommandQueryChannel <
                Reinforced.Tecture.Aspects.Orm.Command, 
                Reinforced.Tecture.Aspects.Orm.Query>,
        CommandQueryChannel <
                Reinforced.Tecture.Aspects.DirectSql.Command,
                Reinforced.Tecture.Aspects.DirectSql.Query>
    { }


, Tecture (, , ). by design . : netstandard2.0. β€” . .NET Core .



, ( ) -. , target framework netstandard2.0. . , Tecture .NET (: windows), .



, . - , .NET Framework, .



, SOLID, O/CP Separation of Concerns. .



β€” . , , . β€” . , , .



, -, . : separated contexts DDD, .



β€” . , - . : . - , Tecture. , .





β€” , -. . Tecture, :



//  
public class Orders : TectureService
    <                       
        Updates<Order>,     //    
        Adds<OrderLine>     //   OrderLine-
    >
{
    private Orders() { }    //    . 
                            // .   .  .

    //  - - -
    public void AddLine(int orderId, int productId, int quantity)   
    {   
        //      
        var order = From<Db>().Get<Order>().ById(orderId);          

        //    
        To<Db>().Update(order)                                      
            .Set(x => x.TotalQuantity, order.TotalQuantity + quantity);

        //   
        To<Db>().Add(new OrderLine {                                
            OrderId = orderId, 
            ProductId = productId, 
            Quantity = quantity});

        //     ,   
        Let<Products>().Reserve(productId, quantity);                

    }                       // .
}


, :



- IoC-. Let<Products>().(...) ( ). 90% IoC- ( ) , . runtime exception. , β€” . , .



Tecture -IoC . , . β€” ( ). Tecture , . . : , Tecture - .



- . , Tecture , . . : . , ISomethingService. . , β€” . , ( virtual ). , .



- , , . β€” dll-, , . . . internal , . , : , β€” . , . "domains", -.



-: . , . , -:



public class Orders : TectureService < Updates<Order>,  Adds<OrderLine> >
{


, . . Order- , OrderLine- ( ). , . , C# . , To<Db>().Delete(order) β€” , : ", , ".



. . Updates<> Adds<> ORM . , , . HKT β€” .



β€” . HKT , , -. god object-. , , , . . β€” TectureService , 10 . , .



-: "Service". β€” . .



Let<>. ? , : Tecture IoC- ITecture ( ). ITecture TectureBuilder . , . , . .



, ITecture Let<>(), . : tecture.Let<Orders>().CreateOne(...), ITecture .



? , ( protected):



  • Let<TService>(), . . -: Do<>. , -.
  • From<TChannel>(): , . , , ITecture;
  • To<TChannel>(): , . , ;


From<> To<> .





EntityFramework: . LINQ, SQL, , , IQueryable. ! - , -. , .Add, .Remove β€” … . β€” SaveChanges, SQL . . EF- ChangesTracker, diff, " , β€” " β€” .



β€” . -. , Read, Write. .



. ? - - ( ), , , . - .



β€” . -, , , , 10 , , ? β€” - .



. . , CQRS, , MediatR, DDD, "Entity Framework Core in Action" - . , . Microsoft β€” , , . Microsoft MVC, Model, View Controller. web-, HttpRequest HttpResponse. , , . . .



Tecture : , β€” .



( )



β€” From<>.



: Tecture , β€” . β€” . . Tecture β€” . .



: , concern- . SELECT . . , , β€” . Repeatable Read. : , , , , - . C# .



fake-, Repository Pattern . . Tecture , : " " , . , β€” , - . . : GetSomethingById, :



//     Id-
public interface IEntity { int Id {get;} }

//    IQueryable ()
public interface IQueryFor<T> 
{ 
    IQueryable<T> All { get; } 
    IQueryable<U> Joined<U>(); 
}

public static class Extensions
{

    //    IQueryFor    
    public static IQueryFor<T> Get<T>(this Read<QueryChannel<Orm.Query>> qr) where T : class
    {
        //       
        var pr = qr.Aspect();
        //     
        return new QueryForImpl<T>(pr);
    }

    //  ById    IQueryFor<T>,  T  int- Id
    public static T ById<T>(this IQueryFor<T> q, int id) where T : IEntity
    {
        return q.All.FirstOrDefault(x => x.Id == id);
    }
}


, :



// , , 
var user = From<Db>().Get<User>().ById(10);


- β€” LINQ, fluent-, , .



( )



β€” From<>(). / … , ? , To<>() . β€” , . β€” .



To<>() Write<...> -, . , . .Add. . .Add β€” . β€” .



. . Tecture Add, .



: - , , . , . EntityFramework. . .



EntityFramework, Save ITecture. .



? . . . , , exception- , . . , .



, . exception-, . . : - -, , , . , , , , -, e-mail- ( ). β€” , . .



, : . , - ? : , , Tecture . ( ORM-, Order ):



public async Task ILikeToMoveIt()
{
    var newOrder = To<Db>().Add(new Order());

    await Save;

    var id = From<Db>().Key(newOrder);
    To<Db>().Delete<Order>().ByPk(id);
}


Save- await. , !



, β€” . Save.ContinueWith(...).






Tecture , . . ( C#), . β€” .



, Tecture . Development Experience .



, , . .



image



.




All Articles