castle-windsor

Castle Windsor - multiple implementation of an interface

↘锁芯ラ 提交于 2019-11-28 08:59:43
While registering components in Castle Windsor, how do we bind specific implementation of an interface to a component that has a dependency on that interface. I know in advance which implementation needs to be used by the component. For example i created a sample console application based on code from several blogs and tutorials. Following is the code. public interface IReport { void LogReport(); } public interface ILogger { string Log(); } public class FileLogger : ILogger { public string Log() { return "Logged data to a file"; } } public class DatabaseLogger : ILogger { public string Log() {

Injecting dependency into CustomAttribute using Castle Windsor

五迷三道 提交于 2019-11-28 06:57:15
In my ASP.Net MVC application I have implemented a Custom ActionFilter to Authorize users. I use CastleWindsor to provide dependency injection into all of the controllers as follows: protected virtual IWindsorContainer InitializeServiceLocator() { IWindsorContainer container = new WindsorContainer(); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); container.RegisterControllers(typeof(HomeController).Assembly); ComponentRegistrar.AddComponentsTo(container); ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container)); return container; }

Castle Interceptors With Fluent Interface

廉价感情. 提交于 2019-11-28 06:31:31
问题 I'm trying to get an interceptor I've written to work, but for some reason it doesn't seem to be instantiating the interceptor when I request my components. I'm doing something like this (forgive me if this doesn't quite compile, but you should get the idea): container.Register( Component.For<MyInterceptor>().LifeStyle.Transient, AllTypes.Pick().FromAssembly(...).If(t => typeof(IView).IsAssignableFrom(t)). Configure(c => c.LifeStyle.Is(LifestyleType.Transient).Named(...). Interceptors(new

Cyclic dependency with Castle Windsor IoC for NHibernate ISession

谁说我不能喝 提交于 2019-11-28 05:40:35
问题 I am using Castle Windsor for my IoC along with NHIbernate in an ASP.NET MVC app. It works great registered as follows (with one exception): container.Register(Component.For<ISessionFactoryBuilder.().ImplementedBy<SessionFactoryBuilder>().LifestyleSingleton()); // Register the NHibernate session factory as a singleton using custom SessionFactoryBuilder.BuildSessionFactory method. container.Register(Component.For<ISessionFactory>().UsingFactoryMethod(k => k.Resolve<ISessionFactoryBuilder>()

Can Windsor's TypedFactoryFacility's implicit delegate factory registration be disabled?

一曲冷凌霜 提交于 2019-11-28 05:33:47
问题 We're using Windsor's typed factory facility and think it's lovely. We use the interface-based factories. However we'd like to disable some sub-sets of the delegate-based factories, specifically the implicitly registered factories . These are counter-intuitive, not because they are delegates, but because they are magically created, and can delay failure. If we have a class which takes a delegate as a dependency class X { public X(Func<int,IPrincipal> d); } And then register it with a

Castle Windsor: A better way to implement 2 levels of (nested) factories?

拥有回忆 提交于 2019-11-28 05:17:11
问题 We have a pattern we've used several times, whereby we implement handlers and factories in separate Dlls. We configure exe's at runtime saying what dlls are loaded, and therefore what handlers are available to the app. We do this because we have custom handling for some customers, also it allows great flexibility because we can quickly develop new handlers in isolation, and test and deploy them with confidence that we haven't even touched any other parts of a running application. We can also

Why have named logger in Log4Net?

家住魔仙堡 提交于 2019-11-28 04:50:30
问题 I have been investigating ways to inject the Log4Net ILog into classes using Castle Windsor. In most examples, I see where Castle Windsor can provide a "facilitator" that provides property injection, and injects the ILogger (not ILog). I have found only one example where contructor injection is used, and the facilitator method is not used (see Castle Windsor dependency injection: Use the caller type as a parameter) In all these examples, it seems Log4Net wants to have a named logger. Most

IoC, Where do you put the container?

五迷三道 提交于 2019-11-28 04:10:07
I'm using castle windsor for a pet-project I'm working on. I'm starting to notice that I need to call the IoC container in different places in my code to create new objects. This dependency on the container makes my code harder to maintain. There are two solutions I've used to solve this problem I tried to create abstract factories as wrappers around the container that I could inject into parts of my application that need to create objects. This works but has some drawbacks because castle has a hard time injecting it's own container as a dependency. So I have to do that by hand, this kind of

Castle Windsor won't inject Logger in a property!

隐身守侯 提交于 2019-11-28 04:02:58
问题 I try to inject log4net in a ILogger property of my service class but the property is always NULL! I've seen this topic but it doesn't help me! How can I get Castle Windsor to automatically inject a property? this is Program.cs CastleContainer.Instance .Install( new RepositoriesInstaller(), new PersistenceInstaller(), new LoggerInstaller(), new FormInstaller(), new ServiceInstaller() ); FrmStart form1 = CastleContainer.Resolve<FrmStart>(new {Id="666" }); I use log4net.config external file and

Castle Windsor IoC in an MVC application

こ雲淡風輕ζ 提交于 2019-11-28 03:30:21
Prepare for a wall of code... It's a long read, but it's as verbose as I can get. In response to Still lost on Repositories and Decoupling, ASP.NET MVC I think I am starting to get closer to understanding this all. I'm trying to get used to using this. Here is what I have so far. Project Project.Web (ASP.NET MVC 3.0 RC) Uses Project.Models Uses Project.Persistence Project Project.Models (Domain Objects) Membership.Member Membership.IMembershipProvider Project Project.Persistence (Fluent nHibernate) Uses Project.Models Uses Castle.Core Uses Castle.Windsor Membership.MembershipProvider :