inversion-of-control

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

Entity Framework ObjectContext with Dependency Injection

别说谁变了你拦得住时间么 提交于 2020-01-21 10:28:54
问题 Well, it seems like I'm stuck in my application structure. Here's what I want to do: UI layer: An ASP.NET webforms website. BLL: Business logic layer which calls the repositories on DAL. DAL: .EDMX file (Entity Model) and ObjectContext with Repository classes which abstract the CRUD operations for each entity. Entities: The POCO Entities. Persistence Ignorant. Generated by Microsoft's ADO.Net POCO Entity Generator. I'd like to create an obejctcontext per HttpContext in my repositories to

Entity Framework ObjectContext with Dependency Injection

Deadly 提交于 2020-01-21 10:28:45
问题 Well, it seems like I'm stuck in my application structure. Here's what I want to do: UI layer: An ASP.NET webforms website. BLL: Business logic layer which calls the repositories on DAL. DAL: .EDMX file (Entity Model) and ObjectContext with Repository classes which abstract the CRUD operations for each entity. Entities: The POCO Entities. Persistence Ignorant. Generated by Microsoft's ADO.Net POCO Entity Generator. I'd like to create an obejctcontext per HttpContext in my repositories to

Injecting new constructor parameters every time a type is resolved using unity

不打扰是莪最后的温柔 提交于 2020-01-17 06:58:28
问题 I've just come across an issue recently where I want new types injected into the requested type every time it is resolved. The current code I have to register the type is container.RegisterType<IFirstT, FirstT>(); container.RegisterType<ISecondT, SecondT>(); container.RegisterType<IInjectableT, InjectableT>() .Configure<InjectedMembers>() .ConfigureInjectionFor<InjectableT>( new InjectionConstructor( container.Resolve<IFirstT>(), container.Resolve<ISecondT>(), ) ); I've now come to realise

MVC 2 Beta DefaultControllerFactory with Areas

醉酒当歌 提交于 2020-01-17 03:30:13
问题 Why default factory WON'T return full name of the controllers (with namespaces)? I'm using Service Locator and autofac. using System.Web.Mvc; using Microsoft.Practices.ServiceLocation; namespace Application.Core.MVC { public override IController CreateController(System.Web.Routing.RequestContext requestContext, string **controllerName**) { return ServiceLocator.Current.GetInstance<IController>(controllerName); } } I had two home controllers (one under area Blog) http://localhost/Home http:/

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

Windsor registration for generic commands/command handlers

China☆狼群 提交于 2020-01-15 11:24:47
问题 Here's my scenario: public static class DomainCommandProcessor { public static void Dispatch<T>(T command) where T : IDomainCommand { var serviceLocator = ServiceLocator.Current; var handler = serviceLocator.GetInstance<IDomainCommandHandler<T>>(); if (handler != null) handler.Handle(command); } } public class FakeGenericCommand<T1, T2> : IDomainCommand { public FakeGenericCommand(T1 first, T2 second) { First = first; Second = second; } public T1 First { get; private set; } public T2 Second {

Windsor registration for generic commands/command handlers

馋奶兔 提交于 2020-01-15 11:24:01
问题 Here's my scenario: public static class DomainCommandProcessor { public static void Dispatch<T>(T command) where T : IDomainCommand { var serviceLocator = ServiceLocator.Current; var handler = serviceLocator.GetInstance<IDomainCommandHandler<T>>(); if (handler != null) handler.Handle(command); } } public class FakeGenericCommand<T1, T2> : IDomainCommand { public FakeGenericCommand(T1 first, T2 second) { First = first; Second = second; } public T1 First { get; private set; } public T2 Second {