castle-windsor

Dynamic selection of interface implementation using IoC

人走茶凉 提交于 2019-11-30 22:32:49
I have a situation where the implementation of an interface is determined at runtime. For example, I check a string and then determine which subclass to use, without IoC it looks like the following: if (fruitStr == "Apple") { new AppleImpl().SomeMethod(); } else { new BananaImpl().SomeMethod(); } Both classes AppleImpl and BananaImpl are implementation of the same interface, say IFruit . How can this be done using IoC/Dependency Injection, especially in Castle Windsor ? NightOwl888 This is the single most-asked question about Dependency Injection, and gets asked over and over again on

How do I get the current Castle Windsor container?

旧时模样 提交于 2019-11-30 22:31:16
问题 I am a Castle Winsor Noob. I have a WebForm project that is a hot mess. I am trying to resolve a dependency to test user registration. How do I get to the current WindsorContainer? IWindsorContainer container = ???; IRegistrationLogic registrationLogic = container.Resolve<IRegistrationLogic>(); _registrationLogic.Register(); Here is my Bootstrapper: public class WindsorConfigTask : ICastleBootstrapperTask { public void Execute() { Container.AddFacility<WcfFacility>(); Container.Register(

Which IOC Container runs in medium trust

纵然是瞬间 提交于 2019-11-30 20:32:35
Hi I am trying to get a website running with Mosso that has Castle Windsor as my IOC, however I am getting the following error. [SecurityException: That assembly does not allow partially trusted callers.] GoldMine.WindsorControllerFactory..ctor() in WindsorControllerFactory.cs:33 GoldMine.MvcApplication.Application_Start() in Global.asax.cs:70 My questions are Does Castle Windsor run under medium trust? Can I download the DLL's without having to recompile with nant? (as I don't have this set up and don't know nant at all) Or is there another IOC that I can use that I can download and works in

Circular 'interfaces' dependencies and Castle-Windsor

China☆狼群 提交于 2019-11-30 18:22:01
问题 I've got components: public interface IFoo { } public interface IBar { } public class Foo : IFoo { public IBar Bar { get; set; } } public class Bar : IBar { public IFoo Foo { get; set; } } I've got Castle-Windsor configuration: Container.AddComponent("IFoo", typeof (IFoo), typeof (Foo)); Container.AddComponent("IBar", typeof (IBar), typeof (Bar)); and failing unit test: [Test] public void FooBarTest() { var container = ObjFactory.Container; var foo = container.Resolve<IFoo>(); var bar =

How can I unit test my controller to make sure Windsor can resolve dependencies when using PerWebRequestLifestyle

核能气质少年 提交于 2019-11-30 18:09:56
I have the following unit test in my application: [TestMethod] public void Windsor_Can_Resolve_HomeController_Dependencies() { // Setup WindsorContainer container = new WindsorContainer(); container.Install(FromAssembly.Containing<HomeController>()); // Act container.Kernel.Resolve(typeof(HomeController)); } The point of this is to make sure I don't have any windsor configuration issues that I won't realize until I access an action on that controller. The problem is that all my object registrations are registered as PerWebRequestLifestyle so I don't get issues with my Entity Framwork Data

How do I tell Windsor to add an Interceptor to all components registered that implement IMustBeIntercepted

孤人 提交于 2019-11-30 15:16:13
If I registered several components with Windsor. IAnimal provides BigAnimal IPerson provides SmellyPerson IWhale provides BlueWhale etc.. pretty standard component registeration all the above types implement IMustBeIntercepted, how do I tell the container add an interceptor to all types that implement IMustBeImplemented so that when Resolve is called it is returned a BigAnimal with an interceptor as defined since it matches. I know I can do this for each one but its extra XML config or programatic config which I want to avoid Simply create an interface like this: public interface

Can't create component as it has dependencies to be satisfied

那年仲夏 提交于 2019-11-30 13:46:20
I am learning DDD, n-Tier, Repositoriess and the likes. Someone pointed me to ASP.NET Boilerplate and I decided to start a test project using that. I have never dealt with dependency injection so this is all new to me, but the DI dependency it uses ius Castle Windsor. Now, I created a Model and from this Model I created an interface. I also added a Service. Whenever I fire up the app it gives me this error: Can't create component 'TestApp.Services.MemberInfo.MemberAppService' as it has dependencies to be satisfied. 'TestApp.Services.MemberInfo.MemberAppService' is waiting for the following

Difference between IWindsorInstaller and AbstractFacility in Castle

≡放荡痞女 提交于 2019-11-30 12:38:55
I've always been using facilities to register my components but noticed the IWindsorInstaller. It both look similar to me and I would like to know what the difference is between both and which one should be used where. Dan, the difference is the following: installers are meant to encapsulate discrete units of registration. In other words you use installers to register application components in the container. There are helpers for that like Configuration class, or FromAssembly class that you can use to either use configuration file, or to autodiscover your installers and run them all in one go

Windsor Container: How to specify a public property should not be filled by the container?

风流意气都作罢 提交于 2019-11-30 11:59:06
When Instantiating a class, Windsor by default treats all public properties of the class as optional dependencies and tries to satisfy them. In my case, this creates a rather complicated circular dependency which causes my application to hang. How can I explicitly tell Castle Windsor that it should not be trying to satisfy a public property? I assume there must be an attribute to that extent. I can't find it however so please let me know the appropriate namespace/assembly. If there is any way to do this without attributes (such as Xml Configuration or configuration via code) that would be

Using Castle Windsor WcfFacility to create client endpoints

不问归期 提交于 2019-11-30 09:46:09
I have created three assemblies. A web site, a WCF service and a contracts assembly that holds the interfaces that the services implement. I would like to use Castle Windsor to create the services for me on the client (website) so that I do not have to have an endpoint in the web.config of the web site for each service that I wish to use. I would like to look at the contract assembly and get all the service interfaces in a namespace. Right now for every service I have something like the following when registering the components with the container. container.Register(Component.For