castle-windsor

How do I control MembershipProvider instance creation/lifetime?

亡梦爱人 提交于 2019-11-27 15:15:01
I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion Of Control using Castle Windsor and I have registered my custom MembershipProvider class as transient (because it's using a service that's transient as well). This means that I want the Membership provider instance recreated on every web request. Currently, it is created only once per application domain so when it tries to access the service it depends on, that service instance is reused while it is not supposed to. Now I need to find a way of having Windsor control the lifetime of my custom

Castle Windsor can't inject an array of interface types

妖精的绣舞 提交于 2019-11-27 15:05:33
问题 I have a class that takes an array of interfaces in the constructor: public class Foo<T1, T2> : IFoo<T1, T2> { public Foo(IBar[] bars) { ... } } My container registration looks as follows: container.Register(AllTypes.Pick().FromAssemblyNamed("...") .WithService.FirstInterface()); container.AddComponent("foo", typeof(IFoo<,>), typeof(Foo<,>)); I have several implementations of IBar, and the container can definately locate them, as calling ServiceLocator.Current.GetAllInstances<IBar>() works

Resolving HttpControllerContext with Castle Windsor

雨燕双飞 提交于 2019-11-27 13:30:33
In the ASP.NET Web API , HttpControllerContext instances provide a lot of information about the current environment, including the URI of the current request. If a service relies on such information (e.g. the request URI), it should be possible to inject that information into the service. This is pretty easy to do using Poor Man's DI: just implement a custom IHttpControllerActivator . However, with Castle Windsor this suddenly becomes very difficult. Previously, I've described a very convoluted way to resolve this issue, but it hinges on the PerWebRequest lifestyle, and it turns out that this

Castle Windsor - IoC registration for open generic interfaces?

China☆狼群 提交于 2019-11-27 13:28:10
问题 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); 回答1: It's called open generic , and yes, Windsor does support that. container.Register(Component .For(typeof(IAdapterFactory<,>))

How to integrate IoC Membership provider with ASP.NET MVC

蹲街弑〆低调 提交于 2019-11-27 11:29:58
I have a custom membership/roles provider that I use in my MVC controllers that I also want to have accessible to ASP.NET MVC, so I can use AuthorizationFilters, etc. Since so many people have implemented custom providers I imagine many people have done this but I haven't figured it out or found postings that address this problem specifically. This post is sort of a flip side of my question. In my case I have my custom provider working well with my controllers, and I want MVC to use it too. My provider is implemented with a IoC/dependency injection design. The provider exposes additional

How to use Castle Windsor with ASP.Net web forms?

偶尔善良 提交于 2019-11-27 11:07:47
I am trying to wire up dependency injection with Windsor to standard asp.net web forms. I think I have achieved this using a HttpModule and a CustomAttribute (code shown below), although the solution seems a little clunky and was wondering if there is a better supported solution out of the box with Windsor? There are several files all shown together here // index.aspx.cs public partial class IndexPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Logger.Write("page loading"); } [Inject] public ILogger Logger { get; set; } } // WindsorHttpModule.cs public class

How can I register a generic decorator using Castle Windsor?

十年热恋 提交于 2019-11-27 09:09:30
I need decorate all based on ICommandHandler<T> types using a corresponding DeadlockRetryCommandHandlerDecorator<T> type I tried this solution, but unfortunately it doesn't work. container.Register( Component.For(typeof(ICommandHandler<>)) .ImplementedBy(typeof(DeadlockRetryCommandHandlerDecorator<>))); container.Register( AllTypes.FromThisAssembly() .BasedOn(typeof(ICommandHandler<>)) .WithService.Base()); How can i register a generic decorator ( DeadlockRetryCommandHandlerDecorator<T> ) to wrap all generic ICommandHandler<T> implementations? currently this is not supported OOTB due to the

Resolving classes without registering them using Castle Windsor

陌路散爱 提交于 2019-11-27 08:53:34
Take the following useless program: class Program { static void Main(string[] args) { IUnityContainer unityContainer = new UnityContainer(); IWindsorContainer windsorContainer = new WindsorContainer(); Program unityProgram = unityContainer.Resolve<Program>(); Program castleProgram = windsorContainer.Resolve<Program>(); } } The UnityContainer will return me an instance of Program, where as the Windsor container will throw a ComponentNotFoundException. I can see arguments for both behaviours and don't mind which I end up with, however Prism V2 Drop 8 (the latest at time of writing) relies on the

ASP.NET-MVC2 Preview 1: Are There Any Breaking Changes?

浪尽此生 提交于 2019-11-27 08:52:36
问题 I was following Steven Sanderson's 'Pro ASP.NET MVC Framework' book. On page 132, in accordance with the author's recommendation, I downloaded the ASP.NET MVC Futures assembly, and added it to my MVC project. Then, without encouragement from the author , I downloaded, installed, and incorporated the ASP.NET MVC2 Preview 1 dlls into my project. Now, I can no longer load the website. That is, when I hit F5 in Visual Studio, I get this error. In retrospect, I think it was a really bad idea to

Castle Windsor Dependency Resolver for MVC 3

爷,独闯天下 提交于 2019-11-27 06:58:29
Since the IoC/DI implementation in MVC 3 is most likely in its final form in the RC, I'm looking for an updated implementation of the DependencyResolver, IControllerActivator and IViewPageActivator using Caste Windsor. Are there any examples out there that have been updated for MVC 3 RC? EDIT #1 Implementing a Windsor dependency resolver is indeed trivial, but there's still something missing. Contrary to Jeff Putz's Ninject example (below), it appears that it's not as simple as that with Windsor. After setting the dependency resolver like so, DependencyResolver.SetResolver(new