Each timer pulse can be considered a new request. Or, if you process several commands in one pulse, each command can be considered a new request.
, ASP.NET WCF, (-, WCF ..), Simple Injector . - Simple Injector Web Forms, MVC, Web API WCF. Simple Injector, - .
Windows, , . , . DI; .
, . Execution Context Scope lifestyle. , ; .
, "" , , . :
public void ProcessCommand(object command) {
using (this.container.BeginLifetimeScope()) {
Type handlerType =
typeof(ICommandHandler<>).MakeGenericType(command.GetType());
dynamic handler = container.GetInstance(handlerType);
handler.Handle((dynamic)command);
}
}
, . , LifetimeScopeLifestyle:
ScopedLifestyle scopedLifestyle = new LifetimeScopeLifestyle();
container.Register<IUnitOfWork, DbContextUnitOfWork>(scopedLifestyle);
v3:
var container = new Container();
container.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle();
container.Register<IUnitOfWork, DbContextUnitOfWork>(Lifestyle.Scoped);
, , , ( ProcessCommand).