inversion-of-control

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 prevent Castle Windsor from injecting property dependencies?

别来无恙 提交于 2019-12-11 02:13:31
问题 Is there a way to prevent Castle Windsor from automatically injecting dependencies into properties (besides the [DoNotWire] attribute)? 回答1: Duplicate: Windsor Container: How to specify a public property should not be filled by the container? See also: http://groups.google.com/group/castle-project-users/browse_thread/thread/f1ec737ff243c19d http://jfromaniello.blogspot.com/2009/07/noninjectable-service.html http://using.castleproject.org/display/Contrib/Castle.Facilities

Injecting Lower Layer Dependency in Presenter in an ASP.NET MVP Application

做~自己de王妃 提交于 2019-12-11 01:59:43
问题 I recently read Phil Haack's post where he gives an example of implementing Model View Presenter for ASP.NET. One of the code snippets shows how the code for the view class. public partial class _Default : System.Web.UI.Page, IPostEditView { PostEditController controller; public _Default() { this.controller = new PostEditController(this, new BlogDataService()); } } However, here the view constructs the instance of the BlogDataService and passes it along to the presenter. Ideally the view

Must I move data dependency out of my Controllers (and into Factories)?

こ雲淡風輕ζ 提交于 2019-12-11 01:56:06
问题 This question can be viewed through a prism of ZF2 + Doctrine + MVC programming practices, or it can be viewed through just an OOP perspective. My concern is about Separation of Concerns, and on removing dependencies. I am using code in my controllers that goes something like this: class MyController { private $em; //entityManager function __construct() { $this->em = DoctrineConnector::getEntityManager(); } function indexAction() { //Input $inputParameter = filter_input(...); //request for

How can i have a IServiceProvider available in ValidationContext parameter of IValidatableObject.Validate method

青春壹個敷衍的年華 提交于 2019-12-11 01:44:25
问题 Controller calls IValidatableObject.Validate internally and passes a ValidationContext object as an argument. I want to use validationContext.GetService() method to get a service object and use it. I can pass this service as a dependency to controller constructor using AutoFac(DI Injection dll). How do i make it availale to the ValidationContext object? This stackoverflow question might contain the answer but i do not understand it fully : Asp.Net MVC3: Set custom IServiceProvider in

How to use autowired (@Autowired) references from main(String[] args) method?

狂风中的少年 提交于 2019-12-11 01:44:20
问题 I am trying to use an autowired reference from main class and am facing : Cannot make a static reference to the non-static field zipCodeLookupService. This is obvious. But I want to know how to handle this situation. What is the correct way of autowiring when main class is involved. My code will be as below - Interface class package com.example.services; public interface IZipCodeLookup { String retriveCityForZip(String zipCode); } Service Class package com.example.services; import org

Why are Producers not inherited in CDI

痞子三分冷 提交于 2019-12-11 01:32:17
问题 Given the following classes private static class ProducedInSubClass { } private static class ProducedInSuperClass { } public static class SuperClass { @Produces public ProducedInSuperClass producedInSuperClass = new ProducedInSuperClass(); } public static class SubClass extends SuperClass { @Produces ProducedInSubClass producedInSubClass = new ProducedInSubClass(); } public static class BeanWithSubClass { @Inject SubClass subClass; @Inject ProducedInSuperClass producedInSuperClass; @Inject

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

Interrupted chain of IoC

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 00:14:55
问题 I am building an application which uses an Abstract Factory pattern to allow runtime determination of which subclass of my IHardwareDevice to create based upon how it responds to a request for identification. I might create Hardware1 or Hardware2. The problem arises in that I want to use a State pattern in these IHardwareDevice objects and I want to have the State be created by the IoC container. Is there a good way to do this without directly calling the IoC container to resolve the State

Wiring MVP with Spring IOC without circular reference?

安稳与你 提交于 2019-12-10 23:55:50
问题 In my MVP applications I use code such as the following to wire my Presenter and View: View view = new View(); Presenter presenter = new Presenter(view); view.setPresenter(presenter); The View class is constructed in a temporarily invalid state, which the call to setPresenter rectifies. I have some code in the View class that throws an IllegalStateException if the View is used without the Presenter being configured. I was hoping Spring could wire this relationship together with a