castle-windsor

Castle Windsor Fluent API: Define dependency explicitly

☆樱花仙子☆ 提交于 2019-12-04 15:33:30
Given the below configuration Container.Register(Component.For<A>().Named("foo")); Container.Register(Component.For<B>().Named("foobar")); Container.Register( AllTypes.Pick() .FromAssemblyNamed("MyAssembly") .If(t => t.Name.EndsWith("ABC")) .Configure(c => c.LifeStyle.Is(LifestyleType.Transient)) .WithService.Select(i => typeof(I)) ); Container.Register( AllTypes.Pick() .FromAssemblyNamed("MyAssembly") .If(t => t.Name.EndsWith("123")) .Configure(c => c.LifeStyle.Is(LifestyleType.Transient)) .WithService.Select(i => typeof(I)) ); If I know that the interface "I" exposes a property "P", and that

Castle Windsor resolving a generic interface

六眼飞鱼酱① 提交于 2019-12-04 14:46:43
I have generic interface with some implementations. interface IBaseInterface<in TObject, out TDetails> { TDetails GetDetails(TObject obj); } abstract class BaseImpl<TObject> : IBaseInterface<TObject, string> { public abstract string GetDetails(TObject obj); } class Impl0 : BaseImpl<decimal> { public override string GetDetails(decimal obj) { return "decimal"; } } class Impl1 : BaseImpl<string> { public override string GetDetails(string obj) { return "string"; } } class Impl2 : BaseImpl<Details> { public override string GetDetails(Details obj) { return "Details"; } } class Impl3<TDetail> :

Resolving dynamically base on name convention in Castle Windsor

可紊 提交于 2019-12-04 13:18:09
I have a seemingly simple use case. There is a ICsvReader component. Let's name it simply Reader here. We load a known set of CSV files and some of them have headers and some don't. Currently there are multiple readers: Reader_Skips1Row, Reader_Skips2Rows etc. Is there a way to register only one component and have Windsor look at the component key, strip the "_Skips..." part and resolve the required component with relevant properties set? I have tried subresolver and facility with no luck. EDIT Yes there is only one implementation but it is used as a dependency and configured to be resolved by

Recommended Castle Windsor/NHibernate stack?

穿精又带淫゛_ 提交于 2019-12-04 13:00:11
I've got a personal (learning) project that uses Castle Windsor (with the NHibernate facility) and NHibernate (and ASP.NET MVC and Moq, and SQL Server 2008, all stuff that I want to learn more about). I attempted to use NHibernate Validator over the weekend, but it needed the 2.1.0Alpha2 build of NHibernate . Since Castle Windsor 1.0RC3 is built against an older version of NHibernate, it all went wrong. I look on the Castle Windsor site, and the combined installer appears to be deprecated, and none of the components look to have been packaged in a while. So: what versions of NHibernate and the

Castle Windsor problem

*爱你&永不变心* 提交于 2019-12-04 12:06:26
I have a problem with castle core, i'm trying to inject two different database connection to specific repositories. public class Repository1 { public Repository1(System.Data.Common.DbConnection conn) { } } public class Repository2 { public Repository2(System.Data.Common.DbConnection conn) { } } Now for example im would like to inject Mysql connection to Repository1 and Oracle connection to repository2. Something like this: container.Register(Component .For<DbConnection>() .ImplementedBy<MysqlConnection>() .Named("mysql")); container.Register(Component .For<DbConnection>() .ImplementedBy

Injecting Dependencies into Domain Model classes with Nhibernate (ASP.NET MVC + IOC)

时光总嘲笑我的痴心妄想 提交于 2019-12-04 11:42:58
问题 I'm building an ASP.NET MVC application that uses a DDD (Domain Driven Design) approach with database access handled by NHibernate. I have domain model class (Administrator) that I want to inject a dependency into via an IOC Container such as Castle Windsor, something like this: public class Administrator { public virtual int Id { get; set; } //.. snip ..// public virtual string HashedPassword { get; protected set; } public void SetPassword(string plainTextPassword) { IHashingService hasher =

MassTransit 2.6.1 Request/Response pattern - Response times out

折月煮酒 提交于 2019-12-04 10:45:59
I'm looking at MassTransit as a ServiceBus implementation to use in a web project. I am playing with the Request/Response pattern and am seeing a long delay between the consumer receiving the message and responding, and the request publisher handling the response; sometimes, it seems like the response is never going to come through (having left it running for 10 minutes, the response has still not come through). the only times that I have seen the handle delegate get called with the response is after a 30 second timeout period and the timeout exception being thrown; in this situation, the

Castle Windsor: PerThread vs PerWebRequest in ASP.NET

只谈情不闲聊 提交于 2019-12-04 10:04:07
A lot of people seem to use the PerWebRequest lifestyle in web apps for managing certain contexts. I have two concerns: PerWebRequest has a dependency on an http module (right?). 2. PerWebRequest has a dependency on HttpContext. I have some ASP.NET code that fires off in a separate thread (and loses HttpContext). It seems that ASP.NET / IIS starts a new thread for each web request. Is there any reason not to just use the PerThread lifestyle and not have to worry about these dependencies? Or is there some advantage to PerWebRequest? 来源: https://stackoverflow.com/questions/6845898/castle-windsor

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

久未见 提交于 2019-12-04 09:48:18
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 MyNamespace.IFoo is abstract. As such, it is not possible to instansiate it as implementation of MyNamespace.IFoo service I'm not really sure what the problem is. But the stack trace shows that in 'DefaultComponentActivator.CreateInstance()', the following condition succeeds and then the error is thrown: if

Using IOC in a remoting scenario

一曲冷凌霜 提交于 2019-12-04 09:18:19
I'm struggling with getting IOC to work in a remoting scenario. I have my application server set up to publish Services (SingleCall) which are configured via XML. This works just like this as we all know: RemotingConfiguration.Configure(ConfigFile, true); lets say my service looks like that (pseudocode) public class TourService : ITourService { IRepository _repository; public TourService() { _repository = new SqlServerRepository(); } } But what I rather would like to have sure looks like this: public class TourService : ITourService { IRepository _repository; public TourService(IRepository