ioc-container

Common Service Registry

做~自己de王妃 提交于 2020-01-21 12:36:52
问题 For a long time now we've been fortunate enough to have the Common Service Locator (CSL) to resolve services from an unknown source. However, there has never been any container-agnostic solution for registering these services in the first place. We've always been faced with the problem of having to couple our composition code to a particular IoC container, and furthermore, be committed to using that container throughout our entire application. I feel I may be trying to achieve the impossible

Common Service Registry

谁说我不能喝 提交于 2020-01-21 12:36:28
问题 For a long time now we've been fortunate enough to have the Common Service Locator (CSL) to resolve services from an unknown source. However, there has never been any container-agnostic solution for registering these services in the first place. We've always been faced with the problem of having to couple our composition code to a particular IoC container, and furthermore, be committed to using that container throughout our entire application. I feel I may be trying to achieve the impossible

How can I dispose every instance object in StructureMap's ObjectFactory?

烂漫一生 提交于 2020-01-21 12:13:49
问题 I'm using StructureMap in my project and when the application finishes running I need to call the Dispose() method on all of the Singleton instances inside the ObjectFactory that implement IDisposable. I cannot find anyway to do it via the StructureMap API. Another thought I had was to get a reference to every instance and call it myself, but I cannot figure out how to loop through all of the instances. 回答1: PS: You might be interested in the deterministic disposal by Autofac IoC container

SessionPerWebRequest UoW SimpleInjector ActionFilterAttribute

天涯浪子 提交于 2020-01-15 19:11:10
问题 I am using SimpleInjector and want to create a UnitOfWork Per WebRequest Using an UnitOfWorkFactory . I want to do this by using an ActionLiterAttribute so that every web request will begin a new UnitOfWork The only problem that I have is to pass the IUnitOfWorkFactory to the ActionFilterAttribute class. There is a similar question about this online but there is a solution given using Ninject , Unfortunately with SimpleInjection there is no equivalent to Bind a filter. This is what I have

How to use/configure Unity Container IOC in my situation

拈花ヽ惹草 提交于 2020-01-14 04:40:23
问题 I have some trouble implementing the Unity IOC into my project reading from config file. Here is what I have 1) ClasslibraryA 2) ClasslibraryB that references ClasslibraryA 3) Winforms App that references ClasslibraryB Note: SomeOther app will reference ClassLibraryA, eg. a web service. ClasslibraryA will have to be configured for IOC depending on where it is used. eg. IDataSource will be different if it is called in the web service and when it is called from a local app. ClasslibraryB will

Spring.Net IoC and Magic Strings

旧时模样 提交于 2020-01-13 19:48:47
问题 I've been thinking about the IApplicationContext.GetObject(string name) method and it seems to rely fairly heavily on magic strings to get objects from the application context. With other containers like StructureMap you can use generics to specify the configuration and request objects but is there a better way than using strings with the Spring.Net IoC container to request objects from the ApplicationContext? 回答1: You could have a wrapper that you call, taking a generic type parameter.

Unity - ResolveAll by name with condition

霸气de小男生 提交于 2020-01-13 16:29:14
问题 I was wondering if it is possible to resolve all dependancies in Unity by some condition on the name that they were registered. For example: Resloving all interfaces registered where the name registered starts with "ProcessA". And if there is no way to do this then perhaps how can i extend Unity to allow this. 回答1: You should be able to use Registrations to do this and I would recommend an extension method rather than extending Unity directly: var matches = c.Resolve<IMyService>(name => name

How to configure Ninject so that it would inject right instance depending on previously injected instance

时光毁灭记忆、已成空白 提交于 2020-01-13 14:04:38
问题 I can't find right words for my question so i will let my code speak instead. I have Repository: class Repository { public Repository(DbContext ctx) { } } then i have this bindings: Bind<IRepository>().To<Repository>(); Bind<DbContext>().To<UserStoreContext>().When... Bind<DbContext>().To<CentralStoreContext>().When... and then i have class that needs to access both db's class Foo { public Repository(IRepository userRepo, [CentralStoreAttribute]IRepository centralRepo) { } } How should i

How to configure Ninject so that it would inject right instance depending on previously injected instance

人盡茶涼 提交于 2020-01-13 14:02:18
问题 I can't find right words for my question so i will let my code speak instead. I have Repository: class Repository { public Repository(DbContext ctx) { } } then i have this bindings: Bind<IRepository>().To<Repository>(); Bind<DbContext>().To<UserStoreContext>().When... Bind<DbContext>().To<CentralStoreContext>().When... and then i have class that needs to access both db's class Foo { public Repository(IRepository userRepo, [CentralStoreAttribute]IRepository centralRepo) { } } How should i

How to do dependency injection to Action Filter on ASP.NET Web API

扶醉桌前 提交于 2020-01-12 04:06:30
问题 I really get stuck on the approach to do dependency injection into action filter of web api. I have an action filter like this: public class AuthorizationAttribute : ActionFilterAttribute { public IApiKeyRepository Repository { get; set; } private Guid GetApiKey(string customerKey) { return Repository.GetApiKey(customerKey); } public override void OnActionExecuting(HttpActionContext actionContext) { } } I would like to do property injection on the property Repository by using Windsor (but it