
Saya terganggu oleh arsitektur tradisional aplikasi bisnis - Saya sudah membicarakan hal ini. Saya mengkritik - saya sarankan. Sekarang saya akan memberi tahu Anda di mana pencarian solusi untuk masalah dari artikel sebelumnya membawa saya.
Saya suka mengulang konsep arsitektur. Sepanjang hidup saya, saya telah mencoba untuk menemukan sesuatu di bidang arsitektur dan desain perangkat lunak yang bekerja dan pada saat yang sama sederhana. Tidak membutuhkan istirahat di otak untuk memahami dan perubahan paradigma radikal. Banyak ide telah terkumpul dan saya memutuskan untuk menggabungkan yang terbaik dari mereka dalam kerangka saya - Reinforced.Tecture. Mengembangkan hal-hal seperti itu adalah sejumlah besar bahan pemikiran, saya ingin membagikannya.
Teks tentang hal-hal teknis seperti itu biasanya sangat membosankan. Sejujurnya saya berusaha untuk tidak membosankan, jadi teks saya ternyata sedikit agresif. Jika Anda tertarik untuk membaca tentang arsitektur aplikasi .NET dengan norma-norma ini, silakan masuk.
: , , - . ( ), , — . . Tecture , . DevRel open source , . , , ( MIT-). , - — .
: . , , , . , . : , , , , , "-" . :
- - Java (, C#) 80-90. — MS- eShopOnContainers, , - -. , peer review ;
- . — , , .
"", "". — . , . , .NET.
: . , 100 UpWork- MVP. , , 30 15 . , , . , production-, -. node/react . , , . long term. " , " .
Sistem eksternal
- : , — , - 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 . Development Experience .

.