"# ServiceFabric.AsyncModel"
I'm now trying to construct a distributed Architecture which treats Micro-Service as a middleware, message will be enqueued to a reliable queue and notify the sender when the message processing is finished.
-
Event Loop
1.1. The event loop from nodejs explained that the process will keep polling for the inputed scripts, callbacks are excuted when the event data is grabbed.
1.2. In service fabric polling is already exsiting in Stateful micro-service. -
Async Notification
2.1. Async notificaiton will do non-blocking action which just means the event message wil be pushed into an another(or the orignal queue) again, you may understand what the "again" means: loop is everywhere.
2.2. Thanks to the classTaskcompeletionsource<T>
, we can do async nitification very easily. -
Immutable
3.1. I learned it from Redux: do not try to mutate an object, if necessary, just create a new one.
3.2. Each tutorial will tell you that immutabe set(dictionary, list, map) is thread-safe, to me, it just make debugging code easily as changes are always not in the current reference.(I'm a beginner.) -
Middleware in Asp.Net Core
4.1. Aspnet core process HttpContext in middlware, if you have read the source code of Aspnet core, you will find middlware is abstracted as a deleagte.
4.2. you may enjoy the design of this kind of middleware because functional programming(curry, function compose) can make middleware more extendable.
Design
If you want to create a modularized app and minimize the dependencies between the different parts of your application, Dependency Injection is a good chioce.
I built a DI of my own:
Functional expression:
compiler = () =>{
return compiler[] => Type => instance;
}
How to use EasyDI:
var box = new EasyTypeContainer();
box.AddDisp<IClassA>(new ClassA());
box.AddDisp<IClassB>(typeof(ClassB));
box.AddDisp<IClassC, ClassC>();
box.AddDisp<IClassD>( factory => {
var para = (IClassC)factory.GetInstance(typeof(IClassC));
var intance = new ClassD(para);
return intance;
});
box.AddDisp<ClassE, ClassE>();
var tracker = box.CreateTracker();
var result = tracker.Track(typeof(ClassE));