castle-windsor

Register Multiple Components for Single Interface Using Castle Windsor

久未见 提交于 2020-01-01 18:05:30
问题 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 message when the container is trying to be built. container.Kernel.Register( Component.For<ISession>().LifeStyle.Transient .UsingFactoryMethod(() =>

Castle Custom Lifestyle per Resolve

懵懂的女人 提交于 2020-01-01 18:04:38
问题 With Castle Windsor, let's say I have the following classes: public class LowLevelComponent { } public class HighLevelComponent { readonly LowLevelComponent LowLevelComponent; public HighLevelComponent(LowLevelComponent lowLevelComponent) { LowLevelComponent = lowLevelComponent; } } public class ComponentBeingResolved { readonly LowLevelComponent LowLevelComponent; readonly HighLevelComponent HighLevelComponent; public ComponentBeingResolved(LowLevelComponent lowLevelComponent,

Castle Custom Lifestyle per Resolve

耗尽温柔 提交于 2020-01-01 18:04:22
问题 With Castle Windsor, let's say I have the following classes: public class LowLevelComponent { } public class HighLevelComponent { readonly LowLevelComponent LowLevelComponent; public HighLevelComponent(LowLevelComponent lowLevelComponent) { LowLevelComponent = lowLevelComponent; } } public class ComponentBeingResolved { readonly LowLevelComponent LowLevelComponent; readonly HighLevelComponent HighLevelComponent; public ComponentBeingResolved(LowLevelComponent lowLevelComponent,

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

北慕城南 提交于 2020-01-01 12:02:30
问题 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

ASP.NET MVC, 'Ticket Required' Attribute

蹲街弑〆低调 提交于 2020-01-01 05:29:07
问题 I am attempting to build a system that allows users to perform certain actions, but their account must have a specific 'Ticket' per time they do it. For instance, suppose they wish to create a Product , they would need a CreateProductTicket . I could simply do this with some 'if' statements, sure, but I want to try a bit more of a robust solution. My structure looks something like this... interface ITicket<T> where T : ITicketable { } My basic goal is to build an Attribute, perhaps like the

Castle Windsor or Spring.NET - advantages and disadvantages [closed]

有些话、适合烂在心里 提交于 2020-01-01 02:25:12
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Yesterday I was reading some articles in this site while I stumbled on an article about this two new IoC tools. Which one should I

Castle Windsor IoC Property Injection simple how-to

自古美人都是妖i 提交于 2019-12-30 18:38:07
问题 OK I think there is maybe too much information about Castle Windsor because looking for these keywords gives me examples of everything, and frankly I don't understand enough about how it works to properly troubleshoot this. I have tried quite a few permutations with little luck at this point. I have an IUnitOfWorkFactory that I want to instantiate as a singleton. So, I install Castle Windsor, write a bit of code like so: iocContainer = new WindsorContainer() .Install(FromAssembly.This()); var

Castle.Windsor and HttpContextWrapper

时光毁灭记忆、已成空白 提交于 2019-12-30 12:17:51
问题 HttpContextWrapper and HttpContextBase, as explained here, were introduced to make HttpContext more mockable/testable. I'm trying to use it with S#arp Architecture, and hitting some problems. My MVC Controllers are set up to accept an HttpContextBase argument in the constructor, and during Application_Start, HttpContextBase is registered with Castle.Windor as follows: container.Register(Component.For<HttpContextBase>().UsingFactoryMethod( () => new HttpContextWrapper(HttpContext.Current)));

Castle.Windsor and HttpContextWrapper

早过忘川 提交于 2019-12-30 12:17:49
问题 HttpContextWrapper and HttpContextBase, as explained here, were introduced to make HttpContext more mockable/testable. I'm trying to use it with S#arp Architecture, and hitting some problems. My MVC Controllers are set up to accept an HttpContextBase argument in the constructor, and during Application_Start, HttpContextBase is registered with Castle.Windor as follows: container.Register(Component.For<HttpContextBase>().UsingFactoryMethod( () => new HttpContextWrapper(HttpContext.Current)));

How does Castle Windsor respond to a class which implements multiple interfaces?

柔情痞子 提交于 2019-12-30 09:40:51
问题 For example I have two interfaces: ICustomerService and IOrderService which each has a couple of functions like GetCustomer, GetOrder, etc. I want one class to implement both interfaces: Server. How does Castle Windsor respond to this? Is it possible in the first place? When I resolve the Server object based on one of the two interfaces, will I get the same object? What happens when I have a constructor that has both interfaces in its parameters? Will there still be one object constructed.