
أنا منزعج من الهندسة التقليدية لتطبيقات الأعمال - لقد تحدثت بالفعل عن هذا. أنتقد - أقترح. الآن سأخبرك إلى أين قادني بحثي عن حلول للمشكلات من المقالة السابقة.
أحب تكرار المفاهيم المعمارية. طوال حياتي كنت أحاول أن أجد شيئًا في مجال الهندسة المعمارية وتصميم البرمجيات يعمل وفي نفس الوقت بسيط. لا يتطلب الأمر استراحة في الدماغ من أجل الفهم وتغيير جذري في النموذج. لقد تراكمت الكثير من الأفكار وقررت الجمع بين أفضلها في إطاري - Reinforced.Tecture. إن تطوير مثل هذه الأشياء هو قدر هائل من الطعام للفكر ، أريد مشاركتها.
عادة ما تكون النصوص حول مثل هذه الأشياء التقنية مملة بشكل رهيب. حاولت بصدق ألا أكون مملاً ، لذلك اتضح أن نصي عدواني قليلاً. إذا كنت مهتمًا بالقراءة حول بنية تطبيقات .NET مع هذه القواعد ، فانتقل إلى.
: , , - . ( ), , — . . Tecture , . DevRel open source , . , , ( MIT-). , - — .
: . , , , . , . : , , , , , "-" . :
- - Java (, C#) 80-90. — MS- eShopOnContainers, , - -. , peer review ;
- . — , , .
"", "". — . , . , .NET.
: . , 100 UpWork- MVP. , , 30 15 . , , . , production-, -. node/react . , , . long term. " , " .
الأنظمة الخارجية
- : , — , - 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 .

.