castle-windsor

registering open generic decorators for typed implementations in castle windsor

白昼怎懂夜的黑 提交于 2019-11-29 16:57:40
While trying to coerce Windsor into wrapping an implementation with a random number of decorators, i've stumbled upon the following: i have 3 decorators and an implementation all using the same interface. if you run this code, windsor resolves icommandhandler<stringcommand> as implementation , which, as far as i can tell, is expected behaviour, because the typed implementation can not be registered with the open typed decorators. However, if you uncomment the line container.Register(Component.For<ICommandHandler<stringCommand>>().ImplementedBy<Decorator1<stringCommand>>()); , all three

How can I incorporate this Castle Windsor DI code into my Controller and Repository code?

谁都会走 提交于 2019-11-29 16:29:29
Note : I can't bountify this question yet (it's too new), but I will reward a good answer with 50 points, and a great answer with 100 (when possible). I need to incorporate DI into my Web API project. I currently have the expected Model and Controller folders/classes, along with corresponding Repository classes. That seemed to work well for awhile, but now I need to use DI with the Controllers so that I can pass an Interface type to the Controllers' constructor. I'm struggling with just how to implement this; that is, how to incorporate the DI "extravaganza" into my existing Model/Controller

Appropriate lifecycle for repository classes using Castle Windsor

微笑、不失礼 提交于 2019-11-29 16:01:16
When I started with Windsor I thought DI would be simple. Now it's causing me more and more confusion. A repository strikes me as a class with a singleton lifecycle. I should have a single instance of a FooRepository to load and save Foos to the database during the application's lifetime. However, each repository holds a reference to a UnitOfWork, which does the dirty checking, works with the database etc. The UnitOfWork has a lifecycle of PerWebRequest - it makes no sense at all for the UnitOfWork to be a singleton, as a singleton instance could (for example) flush the changes made by several

Seemingly circular dependencies causing issues with Castle Windsor

半腔热情 提交于 2019-11-29 15:38:56
I have a IUserService (and other services) that I am registering in bulk in my ServiceInstaller.cs: container.Register( AllTypes.FromAssemblyContaining<UserService>() .Where(type => type.Name.EndsWith("Service")) .WithService.DefaultInterface() .Configure(c => c.LifeStyle.Singleton) ); I then I have IAuthenticationService which I register as in my generic WindsorInstaller.cs file: container.Register(Component.For(typeof (IAuthenticationService)) .ImplementedBy(typeof(AuthenticationService))); Now things were working just fine until I added a public property for IAuthenticationService in my

Register component based on parameter name on requestor in windsor

自作多情 提交于 2019-11-29 14:33:08
I have this interface for using AutoMapper: public interface IMapper { object Map(object source, Type sourceType, Type destinationType); } Then for each type of data, I have a different mapper class , for example: public class UserMapper : IMapper { static UserMapper() { Mapper.CreateMap<User, UserViewModel>(); Mapper.CreateMap<UserViewModel, User>(); } public object Map(object source, Type sourceType, Type destinationType) { return Mapper.Map(source, sourceType, destinationType); } } Then I have IMapper as one of the parametter in my controller class like this: public UsersController

Integrating Castle Windsor with SignalR - how should I approach this?

笑着哭i 提交于 2019-11-29 14:15:32
问题 I am getting started with SignalR, and it works great once everything is configured. However, almost all the applications that I work on use Castle Windsor, so it would be great to be able to use them together. The reason that I want to do this is so that I can use Castle dependencies/services inside of a persistent connection. I dug around in the source code, and it looks like I could either replace DependencyResolver with a Castle based one (i.e., Castle implementing IDependencyResolver),

ASP Web Api - IoC - Resolve HttpRequestMessage

我是研究僧i 提交于 2019-11-29 13:19:43
问题 I am trying to set up Castle Windsor with ASP.NET WebAPI. I am also using the Hyprlinkr package (https://github.com/ploeh/Hyprlinkr) and so need an instance of HttpRequestMessage injected in to one of the dependencies of my controller. I am following this article by Mark Seemann - http://blog.ploeh.dk/2012/04/19/WiringHttpControllerContextWithCastleWindsor.aspx , but I am finding that although the API runs, when I make a call to it, the request just hangs. No error message. It’s as if it’s in

Inject App Settings using Windsor

淺唱寂寞╮ 提交于 2019-11-29 12:43:50
问题 How can I inject the value of an appSettings entry (from app.config or web.config) into a service using the Windsor container? If I wanted to inject the value of a Windsor property into a service, I would do something like this: <properties> <importantIntegerProperty>666</importantIntegerProperty> </properties> <component id="myComponent" service="MyApp.IService, MyApp" type="MyApp.Service, MyApp" > <parameters> <importantInteger>#{importantIntegerProperty}</importantInteger> </parameters> <

Cyclic dependency with Castle Windsor IoC for NHibernate ISession

假装没事ソ 提交于 2019-11-29 11:50:12
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>().BuildSessionFactory("ApplicationServices")).LifestyleSingleton()); container.Register(Component.For

Injecting a primitive property in a base class with Castle Windsor

纵饮孤独 提交于 2019-11-29 11:47:19
I have got the following interface definition: public interface ICommandHandler { ILogger Logger { get; set; } bool SendAsync { get; set; } } I have multiple implementations that implement ICommandHandler and need to be resolved. While Castle Windows automatically injects the Logger property, when an ILogger is injected, I can't find a way to configure the SendAsync property to be set to true by Windsor during the creation of new instances. UPDATE The command handlers implement a generic interface that inherits from the base interface: public interface ICommandHandler<TCommand> :