La arquitectura de las aplicaciones empresariales puede ser diferente

imagen



Me molesta la arquitectura tradicional de las aplicaciones empresariales; ya hablé de esto. Critico, sugiero. Ahora les diré adónde me llevó mi búsqueda de soluciones a los problemas del artículo anterior.



Me gusta iterar sobre conceptos arquitectónicos. Toda mi vida he intentado encontrar algo en el campo de la arquitectura y el diseño de software que funcione y al mismo tiempo sea simple. No requiere una ruptura en el cerebro para la comprensión y un cambio radical de paradigma. Se han acumulado muchas ideas y decidí combinar lo mejor de ellas en mi marco: Tectura reforzada. Desarrollar tales cosas es una gran cantidad de elementos para pensar, quiero compartirlos.



Los textos sobre cosas tan técnicas suelen ser terriblemente aburridos. Honestamente, traté de no ser aburrido, por lo que mi texto resultó ser un poco agresivo. Si está interesado en leer sobre la arquitectura de las aplicaciones .NET con estas normas, ingrese.



Descargo de responsabilidad

. , , .



: , , - . ( ), , — . . Tecture , . DevRel open source , . , , ( MIT-). , - — .



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



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


"", "". — . , . , .NET.



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



Sistemas externos



- : , — , - 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 .



, , . .



imagen



.




All Articles