castle-windsor

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

一世执手 提交于 2019-12-03 03:05:26
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 implementation. Mark Seemann Yes, it would be okay to register components without their interfaces, but not

how to get dependencies injected in constructors in Windows Forms

喜夏-厌秋 提交于 2019-12-03 02:59:00
in asp.net-mvc I have the Windsor Controller Factory that injects all the dependencies into the controllers, but how do you get this in Windows Forms ? for example if have this Form1, how am I going to get an instance of Form1, should I use resolve (which is called ServiceLocator and anti-pattern by some ppl)? public class Form1 { private IBarService _barService; public Form1(IBarService barService) { _barService = barService; } } Yes, in program.cs you should make windsor resolve Form1 . For the sake of being able to view the form in the designer you add an empty constructor and decorate it

What is Castle Windsor, and why should I care?

爷,独闯天下 提交于 2019-12-03 01:30:28
问题 I'm a long-time Windows developer, having cut my teeth on win32 and early COM. I've been working with .Net since 2001, so I'm pretty fluent in C# and the CLR. I'd never heard of Castle Windsor until I started participating in Stack Overflow. I've read the Castle Windsor "Getting Started" guide, but it's not clicking. Teach this old dog new tricks, and tell me why I should be integrating Castle Windsor into my enterprise apps. 回答1: Castle Windsor is an inversion of control tool. There are

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

↘锁芯ラ 提交于 2019-12-02 23:29:14
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.AddComponentLifeStyle(t.FullName, t, LifestyleType.Transient); } } protected override IController

Castle Windsor: is there a way of validating registration without a resolve call?

允我心安 提交于 2019-12-02 22:29:30
My current understanding of Castle Windsor registration is that one can only validate registration by calling Resolve on a root component. But since windsor's component model knows each component's dependencies, it should be possible to test that all dependencies can be satisfied without actually instantiating anything. The main reason for wanting to do this is to have a unit test for registration that doesn't require me to stub components that call external resources on start-up. For example. I have a class Root that has a dependency on IChild: public class Root : IRoot { private IChild child

Proper Hub dependency lifetime management for SignalR and Castle Windsor

走远了吗. 提交于 2019-12-02 21:47:15
I have some SignalR hubs which may need to access some transient and singleton dependencies. Hooking the creation of the Hub is easy and works just fine however SignalR does its own Dispose() call on the created Hub rather than notifying the dependency resolver and letting it get involved in the disposal. This isn't such a big deal if the dependencies are registered singletons, but if they're registered as transients then they'll never get disposed (if that was required) and Windsor will keep them alive until the Windsor container is collected (when the web server is shutting down anyway). I

Avoiding Service Locator Antipattern with legacy app not designed for IOC

泄露秘密 提交于 2019-12-02 20:59:28
I have read often that Service Locators in IOC are an anti-pattern . Last year we introduced IOC (Ninject specifically) to our application at work. The app is legacy, it's very big and it's fragmented. There are lots of ways a class, or a chain of classes can get created. Some are created by the web framework (which is custom), some are created by nHibernate. Lots are just scattered around in weird places. How would we handle the different scenarios and not come up with something thats not at least ServiceLocatorish and not end up with different kernels in different places (scopes like

Castle.Windsor: optional resolution of component from a typed factory

半世苍凉 提交于 2019-12-02 15:28:44
问题 I have a WCF service setup with Castle.Windsor; messages arrive to a dispatcher that send them to the right component (basically a IHandler<Message> with message being a query). However in some cases there is one additional before the handler can act; the message must be completed with data coming from someplace else. What i want is to check whether there exists an injector for the type of my message and if one exists, run it. IInjector<Message> Injector = InjectorFactory.RetrieveInjector

How do I configure a decorator with Castle Windsor?

浪尽此生 提交于 2019-12-02 14:16:27
问题 I have a decorator and actual implementation that looks like this: public interface IAmUsedTwice { void DoSomething(); } public class ForReal: IAmUsedTwice { public SomethingElse Need { get; set; } public ForReal(SomethingElse iNeed) { Need = iNeed; } public void DoSomething() { Console.WriteLine("Realing doing something here"); } } public class SomethingElse {} public class DecoratingIsFun: IAmUsedTwice { private IAmUsedTwice Actual { get; set; } public DecoratingIsFun(IAmUsedTwice actual) {

What is Castle Windsor, and why should I care?

自作多情 提交于 2019-12-02 13:48:07
I'm a long-time Windows developer, having cut my teeth on win32 and early COM. I've been working with .Net since 2001, so I'm pretty fluent in C# and the CLR. I'd never heard of Castle Windsor until I started participating in Stack Overflow. I've read the Castle Windsor "Getting Started" guide, but it's not clicking. Teach this old dog new tricks, and tell me why I should be integrating Castle Windsor into my enterprise apps. Matt Hinze Castle Windsor is an inversion of control tool. There are others like it. It can give you objects with pre-built and pre-wired dependencies right in there. An