inversion-of-control

Autofac in web applications, where should I store the container for easy access?

一笑奈何 提交于 2019-12-17 18:24:56
问题 I'm still pretty new to using Autofac and one thing I miss in the documentation and examples is how to make it easy to get to the configured container from different places in a web application. I know I can use the Autofac controller factory to automatically resolve constructor injected dependencies for controllers, but how about the other stuff you might need to resolve that is not injected yet. Is there an obvious pattern I am not aware of for this? Thank you! 回答1: First of all try not to

2 beans with same name but in different packages; how to autowire them?

百般思念 提交于 2019-12-17 16:28:03
问题 I have an application that has 2 beans with the same name, but which are in different packages. My Spring application fails because it cannot decide on which bean to take. Is there any solution for this? The beans do not currently implement specific interfaces. See below an edited example of the exception: Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'dataTransferHandler' for bean class [aaaaa.ws.handler

Castle Windsor passing constructor parameters

妖精的绣舞 提交于 2019-12-17 15:58:09
问题 I have an IAddress class with a few properties. I then have a concrete type that implements this interface. This concrete type has a couple of different constructors I could use. How can I pass parameter values to one of these constructors at run-time? I cannot use the config file as I will be reusing this concrete type multiple times and each time the parameter values will be different. IWindsorContainer container = new WindsorContainer(new XmlInterpreter()); IAddress address = container

How do I control MembershipProvider instance creation/lifetime?

一个人想着一个人 提交于 2019-12-17 13:05:33
问题 I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion Of Control using Castle Windsor and I have registered my custom MembershipProvider class as transient (because it's using a service that's transient as well). This means that I want the Membership provider instance recreated on every web request. Currently, it is created only once per application domain so when it tries to access the service it depends on, that service instance is reused while it is

How do I control MembershipProvider instance creation/lifetime?

余生长醉 提交于 2019-12-17 13:04:04
问题 I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion Of Control using Castle Windsor and I have registered my custom MembershipProvider class as transient (because it's using a service that's transient as well). This means that I want the Membership provider instance recreated on every web request. Currently, it is created only once per application domain so when it tries to access the service it depends on, that service instance is reused while it is

Binding singleton to multiple services in Ninject

╄→尐↘猪︶ㄣ 提交于 2019-12-17 11:53:08
问题 I have a problem which seems very similar to the one described in http://markmail.org/message/6rlrzkgyx3pspmnf which is about the singleton actually creating more than a single instance if you're accessing it using different service types. I'm using the latest release of Ninject 2 for Compact Framework and the exact issue I'm having is that if I bind the same provider method to: Func<Service> serviceCreator = () => new Service(false); kernel.Bind<IService>().ToMethod(serviceCreator)

Binding singleton to multiple services in Ninject

岁酱吖の 提交于 2019-12-17 11:53:07
问题 I have a problem which seems very similar to the one described in http://markmail.org/message/6rlrzkgyx3pspmnf which is about the singleton actually creating more than a single instance if you're accessing it using different service types. I'm using the latest release of Ninject 2 for Compact Framework and the exact issue I'm having is that if I bind the same provider method to: Func<Service> serviceCreator = () => new Service(false); kernel.Bind<IService>().ToMethod(serviceCreator)

How to use Property Injection with AutoFac?

為{幸葍}努か 提交于 2019-12-17 10:58:43
问题 In a Console application, I'm using Log4Net and in the Main method I'm getting the logger object. Now, I'd like to make this log object available in all my classes by letting all the classes inherit from a BaseClass which has a ILog property and is supposed to be set by Property Injection rather than Constructor Injection. I'm using AutoFac IoC container, how to inject my log Object to the Log property of my every class? What's the best/easiest way to achieve this? Is there any way to

Arguments against Inversion of Control containers

谁说胖子不能爱 提交于 2019-12-17 10:26:25
问题 Seems like everyone is moving towards IoC containers. I've tried to "grok" it for a while, and as much as I don't want to be the one driver to go the wrong way on the highway, it still doesn't pass the test of common sense to me. Let me explain, and please correct/enlighten me if my arguments are flawed: My understanding: IoC containers are supposed to make your life easier when combining different components. This is done through either a) constructor injection, b) setter injection and c)

How to use a DI / IoC container with the model binder in ASP.NET MVC 2+?

南笙酒味 提交于 2019-12-17 09:55:52
问题 Let's say I have an User entity and I would want to set it's CreationTime property in the constructor to DateTime.Now. But being a unit test adopter I don't want to access DateTime.Now directly but use an ITimeProvider : public class User { public User(ITimeProvider timeProvider) { // ... this.CreationTime = timeProvider.Now; } // ..... } public interface ITimeProvider { public DateTime Now { get; } } public class TimeProvider : ITimeProvider { public DateTime Now { get { return DateTime.Now;