castle-windsor

How do I configure a decorator with Castle Windsor?

好久不见. 提交于 2019-12-02 13:13:53
I have a decorator and actual implementation that looks like this: public interface IAmUsedTwice { void DoSomething(); } public class ForReal: IAmUsedTwice { public SomethingElse Need { get; set; } public ForReal(SomethingElse iNeed) { Need = iNeed; } public void DoSomething() { Console.WriteLine("Realing doing something here"); } } public class SomethingElse {} public class DecoratingIsFun: IAmUsedTwice { private IAmUsedTwice Actual { get; set; } public DecoratingIsFun(IAmUsedTwice actual) { Actual = actual; } public void DoSomething() { Console.WriteLine("This is a decorator!"); Actual

Is it correct to have many Castle Windsor containers per application if those containers belong to different tiers?

时间秒杀一切 提交于 2019-12-02 09:52:59
I've been playing around with Castle Windsor lately and realized I could use it to back a container-like object I currently use already. So far I've only read information about an application having only one container instance per application. Is it correct to have many containers per application if those containers belong to different tiers? The reason I ask is because I'd like to take advantage of Windsor's dependency resolution and XML configuration for my own container-like object. I currently use Windsor integration with MonoRail and it didn't seem correct to mix in components that have

Windsor MixIn is a Singleton?

隐身守侯 提交于 2019-12-02 09:43:41
I have a MixIn that requires some state to operate. I am registering it as so.. container.Register(Component.For(Of ICat) _ .ImplementedBy(Of Cat) _ .LifeStyle.Transient _ .Proxy.MixIns(New MyMixin())) When I call container.Resolve(of ICat), I get back a proxy for ICat, which also implements IMixin. However, if I call container.Resolve(of ICat) again, I get a new proxy for ICat, but MyMixin is the SAME instance. (Which makes sense because I didn't tell the container any way to create IMixin) So, IMixin is a Singleton, even though the Component's lifestyle is Transient. How can I tell Windsor,

Castle.Windsor: optional resolution of component from a typed factory

坚强是说给别人听的谎言 提交于 2019-12-02 04:51:17
I have a WCF service setup with Castle.Windsor; messages arrive to a dispatcher that send them to the right component (basically a IHandler<Message> with message being a query). However in some cases there is one additional before the handler can act; the message must be completed with data coming from someplace else. What i want is to check whether there exists an injector for the type of my message and if one exists, run it. IInjector<Message> Injector = InjectorFactory.RetrieveInjector<Message>(); if (Injector != null) { Logger.InfoFormat("IInjector<{0}> OK", input.GetType().Name); Injector

Castle Windsor: How to specify a runtime value as a parameter (E.g. value returned from static function call)

亡梦爱人 提交于 2019-12-02 04:28:49
问题 I want to perform this CODE equivlant in the castle xml config file. // Foo(string name) IFoo f = new Foo(StaticBarClass.Name); XML Now for the XML, I know everything (e.g. the blah) except for the stuff inside the parameter part. What would the parameter part look like? <component id="blah" service="blah" type="blah"> <parameters> <name>StaticBarClas.Name_THAT_I_NEED_HELP_WITH</name> </parameters> 回答1: One approach you could use is to replace the configuration parameters inspector with your

Failure to pass generic arguments with Castle Windsor

一曲冷凌霜 提交于 2019-12-02 04:14:21
There seems to be an issue with passing generic arguments when attempting to create a parametrized instance with Castle Windsor Demo of Failure to Pass Generic Arguments private static void Main(string[] args) { PassGenericParamAtResolutionTime(); Console.ReadLine(); } private static void PassGenericParamAtResolutionTime() { Console.WriteLine("Passing generic argument fails"); var container = new WindsorContainer(); container.Register(Component.For<ISandCoordinator<Simpleton>>() .ImplementedBy<SandCoordinator<Simpleton>>()); var runtimeConstructorParam = new GenericManager<Simpleton>( "This Id

Castle Windsor: How to specify a runtime value as a parameter (E.g. value returned from static function call)

我怕爱的太早我们不能终老 提交于 2019-12-02 01:32:24
I want to perform this CODE equivlant in the castle xml config file. // Foo(string name) IFoo f = new Foo(StaticBarClass.Name); XML Now for the XML, I know everything (e.g. the blah) except for the stuff inside the parameter part. What would the parameter part look like? <component id="blah" service="blah" type="blah"> <parameters> <name>StaticBarClas.Name_THAT_I_NEED_HELP_WITH</name> </parameters> One approach you could use is to replace the configuration parameters inspector with your own variant that can introduce some additional behaviour - here's a quick prototype: public class

IOC on IValidationDictionary with Castle Windsor

狂风中的少年 提交于 2019-12-02 00:08:28
I'm new to Castle Windsor and am just using the latest version. I've created entries for my repositories which are working fine but I have one final dependency that I'm passing into my controller. I've created a ModelStateWrapper which inherits from IValidationDictionary. The ModelStateWrapper takes a ModelStateDictionary in it's constructor so that in my code I can pass the following as an example: IMembershipService _memSvc; IValidationDictionary _validationService; public AccountController() { _validationService = new ModelStateWrapper(this.ModelState); _memSvc = new MembershipService(

Castle Windsor: Register class with internal constructor?

陌路散爱 提交于 2019-12-01 22:25:37
A Castle Windsor question: Is it possible to register a class that has an internal constructor with the container? Thanks Joni Krzysztof Kozmic Yes, it is possible. Default component activator looks only for public constructors. You can either provide custom component activator for that component that would take internal constructor into account, or use for example factory to activate the component: var container = new WindsorContainer() .AddFacility<FactorySupportFacility>() .Register( Component.For<Foo>() .UsingFactoryMethod( () => new Foo() ) ); var foo = container.Resolve<Foo>(); However

Automapper Custom Resolver - Inject Repository into constructor

别来无恙 提交于 2019-12-01 21:23:34
问题 I am trying to create a custom resolver for automapper which needs to access one of my data repositories to retreive the logged in users account. Here is my code so far... public class FollowingResolver : ValueResolver<Audio, bool> { readonly IIdentityTasks identityTasks; public FollowingResolver(IIdentityTasks identitTasks) { this.identityTasks = identitTasks; } protected override bool ResolveCore(Audio source) { var user = identityTasks.GetCurrentIdentity(); if (user != null) return user