castle-windsor

Is it ok to register components in Windsor without specifying an interface?

会有一股神秘感。 提交于 2019-12-04 09:06:51
问题 Is it considered bad form to register components in Windsor without specifying an interface? i.e. container.Register(Component.For<MyClass>().LifeStyle.Transient); as opposed to... container.Register(Component.For<IMyClass>().ImplementedBy<MyClass>().LifeStyle.Transient); I understand the benefits of coding to an interface rather than a concrete implementation however we are finding that we now have lots of interfaces many of them are on classes that realistically will only ever have one

Castle Windsor: How do I register a factory method, when the underlying type isn't accessible to my assembly?

て烟熏妆下的殇ゞ 提交于 2019-12-04 09:04:28
I have a project where my business layer is constructed using DI, but I'm trying to go an additional step and use Windsor to manage object construction. Let's just say I have a pre-existing data layer (that I don't want to modify), that can be accessed via the following interface: interface IDataFactory { IDataService Service { get; } } A series of classes in my business layer depend on the services exposed through IDataFactory: IFactory factory = DataFactory.NewFactory(); IBusinessService service = new ConcreteBusinessService(factory.Service); I understand that in order to register

Why is my Castle Windsor controller factory's GetControllerInstance() being called with a null value?

家住魔仙堡 提交于 2019-12-04 08:28:37
问题 I am using Castle Windsor to manage controller instances (among other things). My controller factory looks like this: public class WindsorControllerFactory : DefaultControllerFactory { private WindsorContainer _container; public WindsorControllerFactory() { _container = new WindsorContainer(new XmlInterpreter()); var controllerTypes = from t in Assembly.GetExecutingAssembly().GetTypes() where typeof(Controller).IsAssignableFrom(t) select t; foreach (Type t in controllerTypes) { _container

Managing RavenDb session in Windsor under NServiceBus

不羁的心 提交于 2019-12-04 07:34:15
I'm using NServiceBus (3.2.2), RavenDB (1.2.2017-Unstable) and Windsor (3.0.0.4001) in an MVC 4 project. I have a IHandleMessages class that handles 3 different messages, and that needs an IDocumentSession, and therefore defines a property such as: public IDocumentSession DocumentSession { get; set; } I've copied the RavenDbUnitOfWork implementation from NServiceBus' website I've registered IDocumentStore, IDocumentSession and IManageUnitsOfWork in my Windsor container as follow: container.Register( Component .For<IManageUnitsOfWork>() .ImplementedBy<RavenUnitOfWork>() .LifestyleTransient() );

Castle Windsor Typed Factory Facility equivalents

一世执手 提交于 2019-12-04 05:12:42
do any other .NET IoC containers provide equivalent functionality to the typed factory facility in Castle Windsor? e.g. if I am using an abstract factory pattern in a WPF application: public class MyViewModel { private IAnotherViewModelFactory factory; public void ShowAnotherViewModel() { viewController.ShowView(factory.GetAnotherViewModel()); } } I don't want to have to create a manual implementation of IAnotherViewModelFactory for every type of ViewModel I wish to show, I want the container to take care of this for me. AutoFac has a feature called Delegate Factories , but as far as I can

Castle Windsor: Force resolver to use specified constructor

人走茶凉 提交于 2019-12-04 04:12:16
Here is the example: interface IComponentA {}; class ComponentA : IComponentA { }; interface IComponentB { }; class ComponentB : IComponentB { }; interface IComponentC { }; class ComponentC : IComponentC { public ComponentC(IComponentA a) { Console.WriteLine("Constructor A"); } public ComponentC(IComponentB b) { Console.WriteLine("Constructor B"); } }; All these components are registered in Castle Windsor container. But class ComponentC has 2 overloaded constructors. Any of them can be used when ComponentC is being activated. I need ComponentC(IComponentB b) constructor to be used. For a

Castle windsor intercepter

廉价感情. 提交于 2019-12-04 04:06:04
问题 I am trying to intercept calls to the Handle method on my command handlers. this process works fine when I explicitly register each command handler, the problem is that my generic registration of the command handlers and the interceptor is not correct. exception: An exception of type 'Castle.MicroKernel.ComponentActivator.ComponentActivatorException' occurred in Castle.Windsor.dll but was not handled in user code Additional information: ComponentActivator: could not proxy TempSearch.Command

Castle Windsor - how to resolve components based on constructor parameters

我是研究僧i 提交于 2019-12-04 03:48:52
Say I have a component like this public class MyComponent { public MyComponent(string name) { } } I basically want to have the provided constructor parameters behave as part of the component identifier when resolving it. If you've never resolved it with that set of parameters, it will instantiate a new one. In other words, I want to somehow modify the following test to succeed: IWindsorContainer container = new WindsorContainer(); container.Register(Component.For<MyComponent>()); MyComponent a1 = container.Resolve<MyComponent>(new { name = "a" }); MyComponent a2 = container.Resolve<MyComponent

What is best practise when instantiating a Castle Windsor container in a class library? [duplicate]

和自甴很熟 提交于 2019-12-04 03:31:32
问题 This question already has answers here : Dependency Inject (DI) “friendly” library (4 answers) Closed 3 years ago . I am wondering where the best place to instantiate the castle Windsor container is in a class library. Should I simply do it in the constructor of the class I am using or is there a single entry point for assemblies that I am unaware of? Thanks. 回答1: The configuration of an injected object graph is entirely dependent on the needs of the application that actually uses it. The

Construtor/Setter Injection using IoC in HttpHandler, is it possible?

半世苍凉 提交于 2019-12-04 03:18:16
问题 I've ran into a rather hairy problem. There is probably a simple solution to this but I can't find it! I have a custom HttpHandler that I want to process a request, log certain info then enter the details in the database. I'm using NUnit and Castle Windsor. So I have two interfaces; one for logging the other for data entry, which are constructor injected. I quickly found out that there is no way to call the constructor as the default parameterless constructor is always called instead. So I