ioc-container

How to manage interface segregation when using an IoC container? [duplicate]

夙愿已清 提交于 2019-12-11 03:59:46
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a small system and i'm currently using structureMap as IoC. I just recently got the point of interface segregation...and I'm wondering now. If I have a certain business object, that will implement say, three interfaces... how should I handle this in the configuration and instatiation of code? Assuming I have two interfaces

Applying generic decorators conditionally in Autofac based on configuration values

半世苍凉 提交于 2019-12-11 03:39:58
问题 I have an application with an command/handler based architecture. I have the following interface: public interface ICommandHandler<TCommand> { void Handle(TCommand command); } There are many non-generic implementations of this interface. Those implementations are wrapped by generic decorators such as: public class ProfilingCommandHandlerDecorator<TCommand> : ICommandHandler<TCommand> { private readonly ICommandHandler<TCommand> decoratee; public ProfilingCommandHandlerDecorator

Where to put my IoC Container configuration in Service Fabric Service?

拥有回忆 提交于 2019-12-11 02:45:39
问题 I was thinking in placing the IoC Container dependencies configuration under RunAsync method in the Service class but I have a bad feeling that's not the right place to go.. Is there any convention in Azure Service Fabric Services to place this type of configurations without causing any sort of conflicts? Also, where would you place the dispose call? Note: I'm using Simple Injector for this but other examples from other IoC containers should do too. 回答1: You can create your IoC container in

Inject Specific Type With Autofac

僤鯓⒐⒋嵵緔 提交于 2019-12-11 02:23:08
问题 I want to inject specific type when some conditions are met. For example, i have got an interface like below. public interface IMyInterface{ } And also two classes that implement this interface public class MyClassA : IMyInterface { } and public class MyClassB : IMyInterface { } Finally i have some service class that gets a constructor parameter as IMyInterface. public class ServiceA{ private IMyInterface _interfaceClass; public ServiceA(IMyInterface interfaceClass){ _interfaceClass =

How to using container.Resolve in Module?

和自甴很熟 提交于 2019-12-11 01:19:47
问题 I am beginner with Autofac. Does anyone know How to using container.Resolve in Module? public class MyClass { public bool Test(Type type) { if( type.Name.Begin("My") ) return true; return false; } } public class MyModule1 : Autofac.Module { protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) { var type = registration.Activator.LimitType; MyClass my = container.Resolve<MyClass>(); //How to do it in Module? my.Test

Dependency Injection Container PHP

做~自己de王妃 提交于 2019-12-11 00:48:40
问题 I've recently learned about the advantages of using Dependency Injection (DI) in my PHP application. However, I'm still unsure how to create my container for the dependencies. Before, I use a container from a framework and I want to understand how is he doing things in back and reproduce it. For example: The container from Zend 2. I understand that the container make class dynamic, he does not have to know about them from the beginning, he checks if he already has that class in his registry

Simple Injector - Custom WebViewPage

天大地大妈咪最大 提交于 2019-12-11 00:40:06
问题 I've a small application (for now) that uses translations. My translation Service is called Translator (ITranslator). My problem is that I don't want to retrieve this class in every controller (which returns a view) so I may use it in my views. I've a similar problem with a ListService (where I store all my SelectListItem lists). CustomWebViewPage public abstract class CustomViewPage<TModel> : WebViewPage<TModel> { readonly IScriptFactory scriptFactory; readonly IMembership membership;

MVC3 Controller constructor + Ninject

匆匆过客 提交于 2019-12-10 21:49:15
问题 I'm at the moment working on a MVC3 Web application and ecountered a new problem with Ninject. I'm using the following code in my controller: public class TestController : Controller { public IRepository<CustomerModel> rep; public TestController(IRepository<CustomerModel> repository) { this.rep = repository; } public ActionResult Index() { return View(); } } And my Ninject Module: public class RepositoryModule : NinjectModule { public override void Load() { Bind(typeof(IRepository<>)).To

Windsor Setter Injection in code

江枫思渺然 提交于 2019-12-10 20:31:59
问题 I'm using Windsor to do IoC in our .Net project, but I'm having difficulties doing setter injection in code. I believe it comes from the fact that I blanket register my components, since eventually I'm hoping that legacy project will be fully IoC compliant and mostly Unit Tested (sweet dreams!). Here is how I'm registering the DAOs: container .Register(AllTypes.FromAssemblyNamed("MyApp.Business") .Where(Component.IsInNamespace("MyApp.Business.Dao")) .WithService.DefaultInterface()); And here

Castle Windsor proxies, implicit interfaces and WPF Binding

不羁的心 提交于 2019-12-10 20:11:49
问题 I am attempting to implement a WPF ViewModel using Castle Windsor Dynamic Proxies. The idea is that I want to supply an interface (IPerson below should suffice as an example), a concrete backing class, and an interceptor (for providing automatic implementation of INotifyPropertyChanged). The interceptor implementation is here: http://www.hightech.ir/SeeSharp/Best-Implementation-Of-INotifyPropertyChange-Ever The problem that I am seeing is that when I bind my models to WPF controls, the