castle-windsor

Castle Windsor - IoC registration for open generic interfaces?

前提是你 提交于 2019-11-28 21:06:18
Does Castle Windsor permit registration of an open generic interface or do I need to register each possible typed instance separately? Example - the below with types T,Z fails upon compilation unless I separately specify T, Z with strong types. container.Register(Component .For<IAdapterFactory<T,Z>>() .ImplementedBy<AdapterFactory<T,Z>>() .LifeStyle.PerWebRequest); It's called open generic , and yes, Windsor does support that. container.Register(Component .For(typeof(IAdapterFactory<,>)) .ImplementedBy(typeof(AdapterFactory<,>)) .LifestylePerWebRequest()); 来源: https://stackoverflow.com

How do I use Windsor to inject dependencies into ActionFilterAttributes

假如想象 提交于 2019-11-28 20:37:10
Having seen how NInject can do it and AutoFac can do it I'm trying to figure out how to inject dependencies into MVC ActionFilters using Castle Windsor At the moment I'm using an ugly static IoC helper class to resolve dependencies from the constructor code like this: public class MyFilterAttribute : ActionFilterAttribute { private readonly IUserRepository _userRepository; public MyFilterAttribute() : this(IoC.Resolve<IUserRepository>()) { } public MyFilterAttribute(IUserRepository userRepository) { _userRepository = userRepository; } } I'd love to remove that static antipattern IoC thing from

Why does Castle Windsor hold onto transient objects?

牧云@^-^@ 提交于 2019-11-28 19:12:28
Recently I noticed my application appears to be eating memory that never gets released. After profiling with CLRProfiler I've found that the Castle Windsor container I'm using is holding onto objects. These objects are declared with the lifestyle="transient" attribute in the config xml. I've found if I put an explicit call to IWindsorContainer.Release(hangingObject) , that it will drop its references. This is causing a problem though, I wasn't expecting that with a transient lifestyle object CastleWindsor would keep a reference and effectively create a leak. It's going to be a rather mundane

Castle Windsor are there any downsides?

巧了我就是萌 提交于 2019-11-28 18:48:59
问题 I have been looking into the Castle project and specifically Windsor. I have been so impressed with what is possible with this technology and the benefits of having a such a loosely coupled system are definitely apparent. The only thing I am unsure of is if using this method has any downsides, specifically in asp.net? for example performance hits, etc. I am trying to make the benefits of this approach visible to my fellow developers here and am being hit with the following comebacks: That is

Dependency Injection in WebAPI with Castle Windsor

£可爱£侵袭症+ 提交于 2019-11-28 16:49:25
问题 I want to implement Dependency Injection in WebApi application using Castle Windsor. I have following sample code - Interface - public interface IWatch { { DateTime GetTime(); } } Following Watch class implements IWatch Interface - public class Watch:IWatch { public DateTime GetTime() { return DateTime.Now; } } WebApi Controller - WatchController as below - public class WatchController : ApiController { private readonly IWatch _watch; public WatchController() { _watch = new Watch(); } //http:

How can I tell the Web API / Castle Windsor routing engine to use a different database instance in my Repository?

别说谁变了你拦得住时间么 提交于 2019-11-28 11:35:22
问题 My understanding of the flow of events with an ASP.NET Web API Castle Windsorized app that uses Models, Repositories, and Controllers: 0) The client calls a REST method via a URI such as: http://localhost:28642/api/platypi/Count 1) Castle Windsor's routing engine maps intercepts that incoming call, sending the registered concrete class that implements the interface platypiController has as an arg in its constructor. 2) That constructor determines which of its methods is to be called (what

How can I incorporate this Castle Windsor DI code into my Controller and Repository code?

…衆ロ難τιáo~ 提交于 2019-11-28 10:29:40
问题 Note : I can't bountify this question yet (it's too new), but I will reward a good answer with 50 points, and a great answer with 100 (when possible). I need to incorporate DI into my Web API project. I currently have the expected Model and Controller folders/classes, along with corresponding Repository classes. That seemed to work well for awhile, but now I need to use DI with the Controllers so that I can pass an Interface type to the Controllers' constructor. I'm struggling with just how

Appropriate lifecycle for repository classes using Castle Windsor

ぐ巨炮叔叔 提交于 2019-11-28 10:17:51
问题 When I started with Windsor I thought DI would be simple. Now it's causing me more and more confusion. A repository strikes me as a class with a singleton lifecycle. I should have a single instance of a FooRepository to load and save Foos to the database during the application's lifetime. However, each repository holds a reference to a UnitOfWork, which does the dirty checking, works with the database etc. The UnitOfWork has a lifecycle of PerWebRequest - it makes no sense at all for the

What is the difference between using the Service Locator anti-pattern and using the Castle Windsor container?\" [closed]

℡╲_俬逩灬. 提交于 2019-11-28 09:23:48
Recently, I have been trying to understand what is the difference between using the Service Locator "anti-pattern" and using the Castle Windsor container. I have found some info here and there on the Internet and I have summarized what I have learned so far in an unfinished blog post . EDIT: Until now I have been thinking that Dependency Injection is all one would need to guarantee separation. But everywhere I look I see a push in the direction of containers such as Castle Windsor. I would like to clearly understand the reasons. Please... Explain this to me like I'm a 6 year old :) Mark

List all types registered with a Castle Windsor container instance

梦想的初衷 提交于 2019-11-28 09:03:10
What's the easiest way of programatically listing registered types in Castle Windsor? Thanks Use IKernel.GetAssignableHandlers(typeof(object)) : IWindsorContainer container = ... foreach (var handler in container.Kernel.GetAssignableHandlers(typeof(object))) { Console.WriteLine("{0} {1}", handler.ComponentModel.Service, handler.ComponentModel.Implementation); } 来源: https://stackoverflow.com/questions/1550190/list-all-types-registered-with-a-castle-windsor-container-instance