castle-windsor

Castle.Windsor lifestyle depending on context?

筅森魡賤 提交于 2019-11-29 02:27:12
问题 I have a web application where many components are registered using .LifestylePerWebRequest() , now I've decided to implement Quartz.NET , a .NET job scheduling library, which executes in separate threads, and not the Request thread. As such, HttpContext.Current yields null . My services, repositories, and IDbConnection were instanced so far using .LifestylePerWebRequest() because it made it easier to dispose of them when the requests ended. Now I want to use these components in both

Are we using IoC effectively?

和自甴很熟 提交于 2019-11-29 02:22:46
问题 So my company uses Castle Windsor IoC container, but in a way that feels "off": All the data types are registered in code, not the config file. All data types are hard-coded to use one interface implementation. In fact, for nearly all given interfaces, there is and will only ever be one implementation. All registered data types have a default constructor, so Windsor doesn't instantiate an object graph for any registered types. The people who designed the system insist the IoC container makes

Castle Windsor ApiController Factory implementation for ASP.NET Web API

十年热恋 提交于 2019-11-29 02:07:10
I know it's possible to use DependancyResolver and register Castle Windsor with MVC but due to the issues described in https://stackoverflow.com/a/4889222/139392 we have stuck to the WindsorControllerFactory method of implementation on our MVC projects. However it looks like the ApiControllers are using some other kind of factory as Castle Windsor is unable to inject the dependencies. Has anyone figured out how to use Castle Windsor with ASP.NET Web API and MVC without using the DependencyResolver? Thanks to Critiano's post and some searching on-line I managed to get it to work here's the code

Castle Windsor - Do I have to release singleton or non-disposable transient objects?

别等时光非礼了梦想. 提交于 2019-11-29 01:31:35
问题 The Castle wiki says at several places I should ALWAYS call container.Release() for components resolved through the container. This obviously makes sense for sophisticated life-style management techniques (e.g. LifeStyle.Pooled) or when using specialized facilities... But do I really have to release singleton (which live until the container is disposed) and non-disposable transient objects? If I step through Release() calls for transient objects or singletons these calls seem to be

What are “ForwardedTypes” in the context of Castle Windsor component registration?

廉价感情. 提交于 2019-11-29 01:26:22
As the subject says, really! What do they do? Forwarded types allow you to have more than one service implemented by a single implementation, for a concrete example say we have two interfaces for working with tree nodes of some sort: public interface INodeAlterationProvider { ... } public interface IChildNodeListProvider { ... } And various components take a dependency on one or both of those interfaces. However in implementing each of those interfaces you discover that their is a lot of shared functionality and want to merge the implementations into a single class along with some other

Using Entity Framework with Castle Windsor

青春壹個敷衍的年華 提交于 2019-11-29 01:08:19
I use the Entity Framework database-first approach to generate a DbContext / POCO model for an MVC application. I want to avoid having dependencies on DbContext in my controllers to enable me to switch to another persistence provider as I need to (for example for unit testing purposes). To do this I want to use the Castle Windsor IoC container. I plan to register DbContext as an IUnitOfWork service and to register a generic IRepository service, implementations of which I will use to access and work with aggregate roots in the model. I'm new to Windsor and haven't been able to find much info

Looks like you forgot to register the http module with Windsor Castle with IIS7

随声附和 提交于 2019-11-29 00:37:46
问题 I am using windsor DI framework in one of my MVC project. The project works fine when I tried to run from Visual Studio 2008. But when i tried to run the project creating an application in IIS7 then I recieved the following error message: Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel" />' to the section on your

Castle Windsor: How do I inject all implementations of interface into a ctor?

怎甘沉沦 提交于 2019-11-29 00:03:31
问题 I've written an interface which is implemented by multiple classes. I want to write a Service class which will have all the registered implementations injected into its ctor. The only solution I can think of is to call the Service Locator within the ctor and ask it to Resolve() all implementations. Ideally I would like something like this - interface IVehicle { void Start(); } class Car : IVehicle { public void Start() { Console.WriteLine("Car started."); } } class Truck : IVehicle { public

Why would you use Windsor AsFactory?

三世轮回 提交于 2019-11-28 23:24:33
Why would you use Castle Windsor factory auto implementation feature: AsFactory() rather then asking for needed interface? Example: container.Register(Component.For<IEmailSender>().ImplementedBy<SmtpEmailSender>()); container.Register(Component.For<IEmailSenderFactory>().AsFactory().LifeStyle.Transient); ... using (var factory = context.GetServiceFactory<IEmailSenderFactory>()) { var emailSender = factory.CreateEmailSender(); emailSender.Send(message); } Why wouldn't you simply write: var emailSender = context.GetServiceFactory<IEmailSender>(); emailSender.Send(message); Effect is the same.

Castle Windsor: Auto-register types from one assembly that implement interfaces from another

杀马特。学长 韩版系。学妹 提交于 2019-11-28 21:39:00
I use Castle Windsor as my IoC container . I have an application that has a structure similar to the following: MyApp.Services.dll IEmployeeService IContractHoursService ... MyApp.ServicesImpl.dll EmployeeService : MyApp.Services.IEmployeeService ContractHoursService : MyApp.Services.IContractHoursService ... I use the XML configuration at the moment, and every time I add a new IService/Service pair, I have to add a new component to the XML configuration file. I want to switch all this over to the fluent registration API but haven't worked out exactly the right recipe to do what I want yet.