simple-injector

Simple Injector pass hard coded values into constructor

六月ゝ 毕业季﹏ 提交于 2019-12-05 02:16:16
In Simple Injector I can do the following: container.RegisterSingle<IAuctionContext>(() => new AuctionContext( new Uri("http://localhost:60001/AuctionDataService.svc/"))); What I am doing here is saying that when IAuctionContext is found, replace it with this new AuctionContext . The problem is that with the call to RegisterSingle , only a single instance of AuctionContext will be used. What I'd like it to be able to pass in a Uri parameter as above but not have the single instance but allow a new instance each time. How is this possible? The value you are trying to inject is a simple hard

Method-level attributed interception with Simple Injector

此生再无相见时 提交于 2019-12-05 01:45:25
问题 With Unity, I'm able to quickly add an attribute based interception like this public sealed class MyCacheAttribute : HandlerAttribute, ICallHandler { public override ICallHandler CreateHandler(IUnityContainer container) { return this; } public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { // grab from cache if I have it, otherwise call the intended method call.. } } Then I register with Unity this way: container.RegisterType<IPlanRepository, PlanRepository>(

Simple Injector - No parameterless constructor defined for this object

荒凉一梦 提交于 2019-12-05 01:31:23
I have a new MVC Web Project which i am usin MVC and WebApi in. I have setup Simple Injector (version 2.5.2 from nuGet) using the following code in my global file // Register Injectors SimpleInjectorConfig.Register(); In my SimpleInjectorConfig.cs file i have public class SimpleInjectorConfig { public static void Register() { // Create the container as usual. Container container = new Container(); // services container.Register<IService, MyService>(); // data container.Register<IRepository, MyRepository>(); // Register your types, for instance using the RegisterWebApiRequest // extension from

How to inject dependencis into WCF Attribute with Simple Injector

廉价感情. 提交于 2019-12-05 00:20:28
问题 I have a bunch of WCF services that works with REST and SOAP. I have created an WCF attribute who checks if the current httpcontext exists, if exists it use cookie authentication, other way it use custom WCF authentication. My attribute looks like this: Public Class AuthRequired Inherits Attribute Implements IOperationBehavior, IParameterInspector Public Sub AddBindingParameters(operationDescription As OperationDescription, bindingParameters As Channels.BindingParameterCollection) Implements

DbContext Lifestyle per Screen/ViewModel (WPF + Simple Injector)

牧云@^-^@ 提交于 2019-12-04 18:43:58
I have an WPF application that adheres command/query pattern and uses EF as an ORM. In my mind, when new ViewModel is created, new instance of DbContext should be created and that same instance should be reused across (injected into) all command/query handlers, which are created within the scope of that particular ViewModel. At the end of ViewModel's lifetime, DbContext should be disposed. How to achieve such a setup with Simple Injector? If you are applying the command/handler and query/handler patterns as described here and here , the most logical thing to do is to scope the lifetime of a

Simple Injector:Factory classes that need to create classes with dependencies

可紊 提交于 2019-12-04 18:30:33
问题 I have a factory class that creates a couple of different types of class. The factory is registered with the container. What is the recommended way of creating the classes inside the factory, given that they also have dependencies. I clearly want to avoid a dependency on the container but if I new those classes then they won't be using the container. e.g. public class MyFactory { public IMyWorker CreateInstance(WorkerType workerType) { if (workerType == WorkerType.A) return new WorkerA

Unable to resolve a controller that was loaded from external dll

走远了吗. 提交于 2019-12-04 15:51:42
问题 I am building a Web API using MVC4 Web API with an IoC container (Simple Injector in this case, but I don't think this problem is related to that container) that should expose a variety of CRUD and query operations. The reason for using IOC in my case is that we are a dev shop and I need to be able to let customers build their own web API controllers to expose the data they need to expose need from our system. Consequently, I was hoping to design my solution in a way that allowed me to

Simple Injector with asp.net mvc 4, load controller from another assembly

被刻印的时光 ゝ 提交于 2019-12-04 14:16:50
I'm developing an asp.net mvc 4 site, using Simple Injector as a Ioc tool. It would be a pluggable architecture. Some controllers and views are in another assembly (another mvc4 application, Plugin.Web.dll). And from the main application, I know the path of Plugin.Web.dll, loading the plugin. container.RegisterMvcControllers(Assembly.GetExecutingAssembly()); container.RegisterMvcAttributeFilterProvider(); container.Options.AllowOverridingRegistrations = true; var appPath = AppDomain.CurrentDomain.BaseDirectory; string[] files = Directory.GetFiles(appPath + "\\Plugins", "*", SearchOption

Configure decorators for generic interfaces and inject all instances to constructor with non generic interface argument in Simple Injector

送分小仙女□ 提交于 2019-12-04 13:54:02
问题 I've been using a pattern very similar to what is described in this excellent article to have commands and queries as objects. I am also using SimpleInjector as the DI container. The only significant difference is that rather that controller take an explicit dependency on some ICommandHandler<TCommand> I want the controllers to take a dependency on an object (a Dispatcher ) which will take a ICommand instance and resolve the correct handler for that command. This will reduce the number of

Using RegisterInitializer to wire event handlers

纵饮孤独 提交于 2019-12-04 13:38:34
问题 I have a WCF service that uses Simple Injector for dependency injection. I want to wire up some event handlers in the container bootstrapper. I have created an interface IStatusChangeNotification : public interface IStatusChangeNotification { event EventHandler<int> JobStatusChange; } My CommandHandler implements IStatusChangeNotification and there are two event handler classes EmailNotification and MmrNotification , each defining a Notify() method. Then in my bootstrap code I have the