simple-injector

How to share instance between decoratee and decorator in the context of ScopedLifestyle.Flowing

主宰稳场 提交于 2021-02-11 12:53:43
问题 I don't understand how to to share instance between decoratee and decorator by using a DI container. The following example illustrates my problem. The context instance is shared between the TransactionCommandDecorator and the Command service. var context = UowFactory.GetUnitOfWork(); var command = new TransactionCommandDecorator( context, new Command(context)); command.Execute(new CommandParams { }); context.dispose(); Basically I need to have a lot of commands that interact with the database

Decorator for creating Scope with ScopedLifestyle.Flowing in Simple Injector

可紊 提交于 2021-01-29 22:27:11
问题 I need some help to understand what it's wrong in my configuration of the container. I based this implementation by using this example. Basically i need to implement some use case as database command based on that interface public interface IDatabaseCommand<TResult, TParam> { TResult Execute(TParam commandParam); } and i want to use a decorator that add the transaction safe functionality. Every command need to use a dedicated DbContext and the transaction has to be executed on that context To

Can we use simple injector for dependency injection in wcf services and How?

不问归期 提交于 2021-01-29 15:47:14
问题 Can we use simple injector for dependency injection in wcf services 回答1: We can use simple injector for dependency injection in wcf services.Here is my demo. After installing this NuGet package, it must be initialized in the start-up path of the application by calling the SimpleInjectorServiceHostFactory.SetContainer method: protected void Application_Start(object sender, EventArgs e) { var container = new Container(); container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

SimpleInjector : Register collection with InstanceCreator

主宰稳场 提交于 2021-01-28 08:14:33
问题 I'm trying to register a collection along with its instanceCreator. I wasn't able to find any overload for the Container.Collection.Register method which accepts an instanceCreator. If i try to run a loop and register a type along with its instanceCreator multiple times using the Container.Register(instanceCreator, lifestyle) , i'm unable to do it because i get the error that type cannot be registerd multiple times. Basically what i'm trying to do is: foreach(var item in items){ Container

Serilog's ILogger injected using Log.ForContext<T>, where T is the consumer

跟風遠走 提交于 2021-01-20 16:11:26
问题 Serilog allows creating a context-aware logger: Log.ForContext<T>() I would like to register Serilog with SimpleInjector in such a way that T is the type of the consumer, i.e. it is which class it is injected in to. e.g. public class Car { public Car(ILogger logger) <= would be injected using Log.ForContext<Car>() { } } I can see this has been done with AutoFac. And looking through the SimpleInjector documentation, there is a very promising overload of RegisterConditional() (with the Func

Serilog's ILogger injected using Log.ForContext<T>, where T is the consumer

隐身守侯 提交于 2021-01-20 16:11:25
问题 Serilog allows creating a context-aware logger: Log.ForContext<T>() I would like to register Serilog with SimpleInjector in such a way that T is the type of the consumer, i.e. it is which class it is injected in to. e.g. public class Car { public Car(ILogger logger) <= would be injected using Log.ForContext<Car>() { } } I can see this has been done with AutoFac. And looking through the SimpleInjector documentation, there is a very promising overload of RegisterConditional() (with the Func

How to change registered (Simple Injector) DbContext's connection string after user's authorization?

余生长醉 提交于 2020-08-09 08:14:43
问题 I'm building ASP.NET Core Web Api with Simple Injector and have the following problem: The data for each user is stored in his individual base (but with the same schema), which is known only after he authorizes himself. So... I can give DbContext it's proper connection string only after user's authorization. What is the best way to accomplish this? For now I am storing the connection string in HttpContext custom claim and am refering to it with a use of a static helper class in DbContext 's