simple-injector

Simple Injector Register All Services From Namespace

空扰寡人 提交于 2019-12-05 17:22:07
问题 My Service Interfaces has a namespace of Services.Interfaces The implementation of the Service Interfaces has a namespace of Web.UI.Services I have 2 service implementations for example IUserService which needs to register to UserService ICountryService which needs to register to CountryService This is how I currently register these services with SimpleInjector. container.Register<IUserService, UserService> (); container.Register<ICountryService, CountryService> (); Problem: If I have over

AOP implemented with the Decorator pattern over a Generic Repository

寵の児 提交于 2019-12-05 17:03:25
I'm trying to build a prototype that applies Aspect Oriented Programming to my project using Decorators. Some portion of my project will use a generic Repository (for simple CRUD), but eventually I'll also incorporate Command and Query handlers (these will perform specific tasks like ProcessCustomerOrders, etc.). Also, the cross-cutting concerns I’d like to example here are Security and Logging. Also, I know that my example code is not the using the Decorator pattern, but is just an example of the code I have in place for this prototype to provide a context. I understand there are other ways

Simple Injector and default AccountContoller dependency issue

痴心易碎 提交于 2019-12-05 14:38:19
I have problem with Simple Injector in my Web Api project. I user default AccountController generated by VS. public AccountController(ApplicationUserManager userManager, ISecureDataFormat<AuthenticationTicket> accessTokenFormat) In my configuration file I register: var container = new Container(); // This is an extension method from the integration package. container.RegisterWebApiFilterProvider(config); container.RegisterWebApiControllers(config); container.Register<IInitializeService, InitializeService>(); container.Register<IFolderRepository, FolderRepository>(); container.Register

“An MVC filter provider has already been registered for a different Container instance.” in Simple Injector 2.6

旧街凉风 提交于 2019-12-05 13:57:02
I previously had the setup for property injection in one of my attributes as Container.RegisterInitializer<PermitAttribute>(initialize => { initialize.QueryProcessor = Container.GetInstance<IQueryProcessor>(); }); And the usage was public class PermitAttribute : ActionFilterAttribute { public IQueryProcessor QueryProcessor { get; set; } } but after updating to simpleinjector 2.6.1 The property injection broke. When I am trying to access QueryProcessor object inside PermitAttribute. It resolves null value where as the Simple Injector configuration still has the same property injection via

Using SimpleInjector Is there a way to replicate RegisterWebApiRequest<T>() with .net 4/webapi 1?

不问归期 提交于 2019-12-05 13:55:05
Following up on this question . I'm working through example of using SimpleInjector and WebAPI. Unfortunately, where I want to utilize WebAPI KB2568167 and KB2915689 prevent me from upgrading to .net 4.5. So I'm stuck using .net 4.0 & WebAPI v1 (4.0.30506.0) at the moment. Is there a way to replicate the RegisterWebApiRequest<T>() scoping with the older version of WebAPI? While I the nu-get packages only contain .net 4.5 versions, I was able to download the code and get a framework 4.0 compile without much trouble. When calling var container = request.GetDependencyScope() in my Message Handler

SimpleInjector mixed lifestyle for per web request and lifetime scope

爱⌒轻易说出口 提交于 2019-12-05 13:11:06
I am using Simple Injector as my IoC container and employ the following technique to enable registering a "mixed" lifestyle for some objects as both per web request or per thread. interface IUnitOfWork { } interface IWebUnitOfWork : IUnitOfWork { } interface IThreadUnitOfWork : IUnitOfWork { } class UnitOfWork : IWebUnitOfWork, IThreadUnitOfWork { } container.RegisterPerWebRequest<IWebUnitOfWork, UnitOfWork>(); container.RegisterLifetimeScope<IThreadUnitOfWork, UnitOfWork>(); container.Register<IUnitOfWork>(() => container.GetInstance<UnitOfWork>()); // Register as hybrid PerWebRequest /

How to change dependency registration at run time using simple injector?

戏子无情 提交于 2019-12-05 09:37:51
I'm using the Simple Injector IoC framework, and I would like to be able to change the dependency registration at run time. For example, I have two implementations, A and B , of interface I . Implementation A is registered at app start, but depending on some flag which can change during runtime, I would like to switch the implementation. We are currently doing this the OnActionExecuting event of our BaseController , which all of our controllers inherit from. Here is the sample code of what I am trying to do. protected override void OnActionExecuting( ActionExecutingContext filterContext) { if

How to do a registration in Simple Injector after a GetInstance call / Alternate solution?

帅比萌擦擦* 提交于 2019-12-05 07:26:20
Consider the following example: public class CommunicationClient : IClient { public CommunicationClient(IServerSettings settings) { ... } // Code } public class SettingsManager : ISettingsManager { SettingsManager(IDbSettingManager manager) // Code public IDictionary<string, string> GetSettings() { ... } } Problem : While performing registrations (using SimpleInjector ), I need to provide values that are obtained from an instance of SetingsManager and fill ServerSettings instance (concrete type for IServerSettings ) but if I call GetInstance<ISettingsManager> before registering

Simple Injector conditional injection

北城余情 提交于 2019-12-05 04:53:09
Lets say I have two Controllers: ControllerA and ControllerB. Both of those controllers accept as parameter IFooInterface. Now I have 2 implementation of IFooInterface, FooA and FooB. I want to inject FooA in ControllerA and FooB in ControllerB. This was easily achieved in Ninject, but I'm moving to Simple Injector due to better performance. So how can I do this in Simple Injector? Please note that ControllerA and ControllerB resides in different assemblies and are loaded dynamically. Thanks The SimpleInjector documentation calls this context-based injection . As of version 3, you would use

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 02:19:07
问题 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