castle-windsor

Why use IKernel over IWindsorContainer?

自闭症网瘾萝莉.ら 提交于 2019-12-04 23:32:50
I have seen in several code examples where people have used IKernel rather than use IWindsorContainer . Why is this? Here is one example: http://docs.castleproject.org/(S(kwaa14uzdj55gv55dzgf0vui))/Windsor.Windsor-tutorial-part-two-plugging-Windsor-in.ashx In the above example it came to bite me because I added a subresolver Container.Kernel.Resolver.AddSubResolver( new CollectionResolver(Container.Kernel, true)); that will allow me to inject collections... but yet it wasnt working. I figured out that because just the IKernel was being used it couldnt use the full features of Windsor. Why

Castle Windsor resolving and generics

不想你离开。 提交于 2019-12-04 22:31:43
问题 I have the following: public interface ISubject { ... } public class Subject<T> : ISubject { ... } public class MyCode<T> { ... pulic void MyMethod() { var item = container.Resolve<ISubject>(); //????? how do I pass in T } ... } In this case how do i do the resolve. Cheers Anthony 回答1: vdhant - That's not how containers are meant to be used. You want to use ISubject , right?. Then if you passed T you're breaking your abstraction, because your caller must know that ISubject , is actually a

Can I use WcfFacility with WCF Test Client?

主宰稳场 提交于 2019-12-04 20:52:32
I have a WCF Service Library containing a custom ServiceHostFactory derived from DefaultServiceHostFactory. I can't get the test client to use this factory. I just get the "no parameterless constructor was found" error. Here's my hosting enviroment configuration: <serviceHostingEnvironment> <serviceActivations> <add service="TestService.WcfLibrary.TestService" relativeAddress="/TestService.svc" factory="TestService.WcfLibrary.TestServiceHostFactory, TestService.WcfLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </serviceActivations> </serviceHostingEnvironment> Note that I

How can I get Castle Windsor to automatically inject a property?

萝らか妹 提交于 2019-12-04 19:53:30
问题 I have a property on my classes for logging service. private ILogger logger = NullLogger.Instance; public ILogger Logger { get { return logger; } set { logger = value; } } And I have this in my component registration: container.AddFacility<LoggingFacility>(x => new LoggingFacility(LoggerImplementation.Log4net)); However, Windsor doesn't seem to inject the Logger - am I missing something? 回答1: The lambda parameter for AddFacility is actually a creation callback (it gets called when the

WCF Service Library hosted as a Windows Service using Castle.Windsor 3.0 issue

淺唱寂寞╮ 提交于 2019-12-04 19:13:20
I am wanting to host my WCF Service Library in a windows service. Although it will be communicating to another wcfservice over a local network. I am having great difficulty in finding recent, up-to-date documentation or help to configure the solution for this purpose. Can anyone advise: a) What the preferred endpoint for this kind of connection? (The other WCF service is hosted using a basicHttpBinding) - this in itself lends itself well to configuring the Castle container through hijacking the global.asax. However, hosting this solution in a windows service means i no longer have access to a

WPF + Castle Windsor + MVVM: Locator-DataContext

半腔热情 提交于 2019-12-04 18:47:44
Edit: I have found one method to do this but I'm not sure if it is the best way. In WindsorContainer initialization, first I register viewmodel: container.Register(Component.For<CentrosViewModel>().LifeStyle.Transient); and later I register the View container.Register(Component.For<CentrosAdminView>().LifeStyle.Transient.DependsOn(Property.ForKey("DataContext") .Eq(ViewModelLocator.Centrosviewmodel))); And definition of property ViewModelLocator.Centrosviewmodel is: public static CentrosModel Centrosviewmodel { get { return App.container.Resolve<CentrosViewModel>(); } } End Edit I'm trying to

Dependency Injection for Handlers and Filters in ASP.NET Web API

≯℡__Kan透↙ 提交于 2019-12-04 17:47:59
问题 I am trying to wire up my Web Api project to use Castle Windsor for IoC I have done that for my controllers by following this excellent article. I am now trying to get dependencies injected into my DelegatingHandler and ActionFilterAttribute I have tried to copy the techniques used for filters in regular ASP.Net MVC but they don't seem to apply in Web Api has anyone managed to get this working? I'm not sure what the relevant extension point is in the Web Api I have seen this being suggested

Register Multiple Components for Single Interface Using Castle Windsor

狂风中的少年 提交于 2019-12-04 17:12:46
I am trying to register multiple NHibernate ISessions (multiple databases) by using the code below. I am getting "There is a component already registered for the given key Castle.MicroKernel.Registration.GenericFactory`1[[NHibernate.ISession, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4]]" as the error message when the container is trying to be built. container.Kernel.Register( Component.For<ISession>().LifeStyle.Transient .UsingFactoryMethod(() => sessionFactoryOne.OpenSession() ).Named("ISession+sessionOne")); container.Kernel.Register( Component.For

Castle Custom Lifestyle per Resolve

我怕爱的太早我们不能终老 提交于 2019-12-04 16:59:05
With Castle Windsor, let's say I have the following classes: public class LowLevelComponent { } public class HighLevelComponent { readonly LowLevelComponent LowLevelComponent; public HighLevelComponent(LowLevelComponent lowLevelComponent) { LowLevelComponent = lowLevelComponent; } } public class ComponentBeingResolved { readonly LowLevelComponent LowLevelComponent; readonly HighLevelComponent HighLevelComponent; public ComponentBeingResolved(LowLevelComponent lowLevelComponent, HighLevelComponent highLevelComponent) { LowLevelComponent = lowLevelComponent; HighLevelComponent =

What should be the strategy of unit testing when using IoC?

亡梦爱人 提交于 2019-12-04 16:22:40
问题 After all what I have read about Dependency Injection and IoC I have decided to try to use Windsor Container within our application (it's a 50K LOC multi-layer web app, so I hope it's not an overkill there). I have used a simple static class for wrapping the container and I initialize it when starting the app, which works quite fine for now. My question is about unit testing. I know that DI is going to make my life much easier there by giving me the possibility of injecting stub / mock