castle-windsor

Usage of IoC Containers; specifically Windsor

Deadly 提交于 2019-11-27 01:02:29
I think the answer to this question is so obivous that noone has bothered writing about this, but its late and I really can't get my head around this. I've been reading into IoC containers (Windsor in this case) and I'm missing how you talk to the container from the various parts of your code. I get DI, I've been doing poor mans DI (empty constructors calling overloaded injection constructors with default parameter implementations) for some time and I can completely see the benefit of the container. However, Im missing one vital piece of info; how are you supposed to reference the container

IoC: Castle Windsor and WebAPI

↘锁芯ラ 提交于 2019-11-26 22:53:47
问题 I have an MVC4 site using Castle Windsor that I want to add some WebAPI calls to, so I start digging around a little bit on the interwebs. Now I don't know the ins and outs of IoC; I followed a tutorial for how to set up Castle Windsor on my project, injecting the IUnitOfWorkFactory and the IApplicationService as public properties in a base controller, and a few other interfaces as needed in the controller constructors. It works swimmingly, so I've never had to do more with it. Everywhere

Windsor LifeStyle - Shared instance per Graph

我们两清 提交于 2019-11-26 22:10:34
问题 I have 2 types of ViewModel's public class ViewModelA { IService service; private ViewModelB childViewModel; public ViewModelA(IService service,ViewModelB childViewModel) { this.service = service; this.childViewModel = childViewModel; } public ViewModelB ChildViewModel { get { return childViewModel; } } } public class ViewModelB { IService serivce; public ViewModelB(IService service) { this.service = service; } } I have a Service registered into a Windsor Container : public class Service :

Database injection into a validation attribute with ASP MVC and Castle Windsor

浪子不回头ぞ 提交于 2019-11-26 18:31:53
问题 I need some help - I am trying to use a custom validation attribute in an ASP.NET MVC web project that needs to make a database call. I have windsor successfully working for the controllers and the IRepository interface is injected normally. The problem arrises when I need to inject the repository into the attribute class. The attribute class has the following code: public class ValidateUniqueUrlNodeAttribute : AbstractValidationAttribute { private readonly string message; private readonly

How to use Castle Windsor with ASP.Net web forms?

不羁岁月 提交于 2019-11-26 17:59:19
问题 I am trying to wire up dependency injection with Windsor to standard asp.net web forms. I think I have achieved this using a HttpModule and a CustomAttribute (code shown below), although the solution seems a little clunky and was wondering if there is a better supported solution out of the box with Windsor? There are several files all shown together here // index.aspx.cs public partial class IndexPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Logger.Write(

Windsor castle Injecting properties of constructed object

為{幸葍}努か 提交于 2019-11-26 17:08:32
问题 Some dependency injection containers enable you to inject configured services into an already constructed object. Can this be achieved using Windsor, whilst taking account of any service dependencies there may be on the target object? 回答1: No, it can't. 回答2: This is an old question but Google led me here recently so thought I would share my solution lest it help someone looking for something like StructureMap's BuildUp method for Windsor. I found that I could add this functionality myself

Resolving HttpControllerContext with Castle Windsor

烈酒焚心 提交于 2019-11-26 16:23:15
问题 In the ASP.NET Web API, HttpControllerContext instances provide a lot of information about the current environment, including the URI of the current request. If a service relies on such information (e.g. the request URI), it should be possible to inject that information into the service. This is pretty easy to do using Poor Man's DI: just implement a custom IHttpControllerActivator. However, with Castle Windsor this suddenly becomes very difficult. Previously, I've described a very convoluted

How to integrate IoC Membership provider with ASP.NET MVC

邮差的信 提交于 2019-11-26 15:36:33
问题 I have a custom membership/roles provider that I use in my MVC controllers that I also want to have accessible to ASP.NET MVC, so I can use AuthorizationFilters, etc. Since so many people have implemented custom providers I imagine many people have done this but I haven't figured it out or found postings that address this problem specifically. This post is sort of a flip side of my question. In my case I have my custom provider working well with my controllers, and I want MVC to use it too.

How can I register a generic decorator using Castle Windsor?

对着背影说爱祢 提交于 2019-11-26 14:32:25
问题 I need decorate all based on ICommandHandler<T> types using a corresponding DeadlockRetryCommandHandlerDecorator<T> type I tried this solution, but unfortunately it doesn't work. container.Register( Component.For(typeof(ICommandHandler<>)) .ImplementedBy(typeof(DeadlockRetryCommandHandlerDecorator<>))); container.Register( AllTypes.FromThisAssembly() .BasedOn(typeof(ICommandHandler<>)) .WithService.Base()); How can i register a generic decorator ( DeadlockRetryCommandHandlerDecorator<T> ) to

Resolving classes without registering them using Castle Windsor

依然范特西╮ 提交于 2019-11-26 14:21:35
问题 Take the following useless program: class Program { static void Main(string[] args) { IUnityContainer unityContainer = new UnityContainer(); IWindsorContainer windsorContainer = new WindsorContainer(); Program unityProgram = unityContainer.Resolve<Program>(); Program castleProgram = windsorContainer.Resolve<Program>(); } } The UnityContainer will return me an instance of Program, where as the Windsor container will throw a ComponentNotFoundException. I can see arguments for both behaviours