castle-windsor

Multi tenancy with Windsor

Hi everybody! I need to implement multi-tenancy and i like the way it is solved here. The problem implementing this scenario (in my project) is that the following code snippet var handlerSelectors = windsorContainer.ResolveAll<IHandlerSelector>(); gives me something ( {Castle.MicroKernel.IHandlerSelector[0]}). The following snippet...

Trouble using IAuthorizationPolicy with WCF and Castle-Windsor

I'm currently using Castle-Windsor with the WCF Facility to inject all my WCF services. I've just started adding permission requirements using a custom IAuthorizationPolicy, which seems to work when done on a per-method basis on the service, but when the service class itself is marked up with the requirements, I get an exception thrown. ...

Where should I store a reference to my DI container?

I'm wondering how I should store/reference my dependency injection container(s). Is it alright to have a container be a static property on a static class? Or should I have the container be an instance variable on the application? I'm wondering what the pros and cons of each option are, and what is the best practice for this in web, mvc, ...

Castle Windsor: Problem with Multiple Constructors

Hello stackoverflow! Long-time reader first time writer here. I am currently undertaking a conversion from to the use of Ninject to the current release of Castle Windsor for a simple C# .NET application. For the most part, the conversion has gone well and the implementation of the containers has executed flawlessly. I am however hav...

Castle Windsor auto registration

I currently have the following registration set up private static void AddFrameworkComponentsTo(IWindsorContainer container) { container.AddComponent<ITypeConverter, TypeConversionFacade>(); container.AddComponent<Framework.Conversion.ITypeConverter<string, int>, StringConverter>(); container.AddComponent<Framework.Conversio...

Castle Windsor IoC: How to Initialize Service and Repository Layer

Configuration: component id="customerService" service="MyApp.ServiceLayer.ICustomerService`1[[MyApp.DataAccess.Customer, MyApp.DataAccess]], MyApp.ServiceLayer" type="MyApp.ServiceLayer.CustomerService, MyApp.ServiceLayer" **Controller:** private ICustomerService _service; public CustomerController() { ...

castle IOC - resolving circular references

Hi quick question for my MVP implementation: currently I have the code below, in which both the presenter and view are resolved via the container. Then the presenter calls View.Init to pass himself to the view. I was wondering however if there is a way to let the container fix my circular reference (view -> presenter, presenter -> vie...

Register Multiple Components for Single Interface Using Castle Windsor

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...

Castle Windsor: how to know that the container has been initialized or configured ?

Hello. I'm using Castle Windsor with a configuration from my App.config file. In the code I use : IWindsorContainer container = new WindsorContainer(new XmlInterpreter()); to get the container. But for some configurations of my application I don't want to use CastleWindsor (for some migration issues...) and therefore, I don't wan...

Should controller lifestyle always be transient in Windsor configuration for ASP.NET MVC?

I ran into a problem where I had an Html.DropDownList in my view that would postback the selected value the first time I submitted the form, but each subsequent postback would only post data from the initial postback. So I added lifestyle="transient" to the component element where I had configured my controller for castle windsor, which ...

What's the best way to initialize an MVC Controller with multiple parameters of the same type using Castle Windsor?

In my MVC application, I'm registering all of my controllers using reflection in the Application_Start handler. This basically creates all types that are used on any controller parameter and adds it to the container. I now have a situation where I have multiple parameters on my controller that are of the same type. Here is a simple exam...

String format for Castle DictionaryAdapter

I'm using Castle DictionaryAdapter in order to get the application settings from the app.config as an interface ( based on Getting rid of strings (3): take your app settings to the next level ): public interface ISettings { int MaxUsers { get; } string FeedbackMail { get; } DateTime LastUserLogin { get; } } app.config <?xml ver...

How to I make castle windsor automatically register controllers that don't have any dependencies?

I know I can specify it in the configuration XML, but I'd like to not have to do so for every controller. For example: I have a controller without any dependencies being injected, but I'd rather not type out the XML component section in the config file or register it programmatically. Any ideas, suggestions, examples? Thanks for all the ...

Windsor Castle IoC, how to register IBaseService<TObject> to BaseService<TObject, TRepository>

I have something like this: public interface IBaseService<TObject> public class BaseService<TObject, TRepository> : IBaseService<TObject> where TRepository : IRepository<TObject> I need to register BaseService To IBaseService (the IRepository<> is registered) ...

ASP.NET MVC & Windsor.Castle: working with HttpContext-dependent services

I have several dependency injection services which are dependent on stuff like HTTP context. Right now I'm configuring them as singletons the Windsor container in the Application_Start handler, which is obviously a problem for such services. What is the best way to handle this? I'm considering making them transient and then releasing th...

Castle Windsor: How to register internal implementations

This registration works when all the implementations of IService are public: AllTypes .Of<IService>() .FromAssembly(GetType().Assembly) .WithService.FirstInterface() For example: public interface IService {} public interface ISomeService : IService {} public class SomeService : ISomeService {} Resolving ISomeService ret...

Castle Windsor: UsingFactoryMethod can't instantiate with a weird error

When I use this registration: container.Register( Component .For<IFooFactory>() .ImplementedBy<FooFactory>(), Component .For<IFoo>() .UsingFactoryMethod(kernel => kernel.Resolve<IFooFactory>().CreateFoo()) ); I get this exception: Castle.MicroKernel.ComponentRegistrationException: Type MyNam...

How to register a uri dependency to return HttpContext.Current.Request.Url using Castle Windsor?

I'm new to Castle Windsor, so go easy!! I am developing an MVC web app and one of my controllers has a dependency on knowing the current request Url. So in my Application_Start I initialise a WindsorContainer (container below), register my controllers and then try the following... container.AddFacility<FactorySupportFacility>(); conta...

Parameter unexpectedly initialized when invoked from unit test

I have a unit test invoking a constructor, passing in a "null" on purpose to test the handling of the null. I expect the method invoked to throw an ArgumentNullException, but when I step through the code, I see the parameter has actually been initialised. This has me stumped, although my gut says it has something to do with the DI cont...

Windsor Resolving generic service SubTypes

interface IFoo<T> { } interface IBar { } class BarImpl : IBar { } class FooImplA : IFoo<IBar> { } class FooImplB : IFoo<BarImpl> { } container.Register( AllTypes.Of(typeof(IFoo<>)).From(assem) .WithService.FirstInterface()); var bars = container.ResolveAll<IFoo<BarImpl>>(); Is there anyway to setup the Windsor contain...