castle-windsor

Why would you use Windsor AsFactory?

孤街醉人 提交于 2019-12-18 02:18:56
问题 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

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

痞子三分冷 提交于 2019-12-18 00:31:47
问题 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

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

只愿长相守 提交于 2019-12-18 00:31:40
问题 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

ASP.NET MVC & Windsor.Castle: working with HttpContext-dependent services

十年热恋 提交于 2019-12-17 23:25:58
问题 I have several dependency injection services which are dependent on stuff like HTTP context. Right now I'm configuring them as singletons the Windsor container in the Application_Start handler, which is obviously a problem for such services. What is the best way to handle this? I'm considering making them transient and then releasing them after each HTTP request. But what is the best way/place to inject the HTTP context into them? Controller factory or somewhere else? 回答1: With Castle Windsor

Castle Windsor IOC: Passing constructor parameters to child components

落爺英雄遲暮 提交于 2019-12-17 16:29:26
问题 The following code is for demo purposes only. Lets say i have 2 components (businessService, and dataService), and a UI class. UI class needs a business service, businessService needs a dataService, and dataService relies on a connectionString. Form the UI class i need to resolve the business service, so i am writing the below code: var service = container.Resolve<BusinessService>(new { dependancy = "con string 123" })); notice that dependancy is the connectionString constructor parameter.

Castle Windsor passing constructor parameters

妖精的绣舞 提交于 2019-12-17 15:58:09
问题 I have an IAddress class with a few properties. I then have a concrete type that implements this interface. This concrete type has a couple of different constructors I could use. How can I pass parameter values to one of these constructors at run-time? I cannot use the config file as I will be reusing this concrete type multiple times and each time the parameter values will be different. IWindsorContainer container = new WindsorContainer(new XmlInterpreter()); IAddress address = container

How do I control MembershipProvider instance creation/lifetime?

一个人想着一个人 提交于 2019-12-17 13:05:33
问题 I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion Of Control using Castle Windsor and I have registered my custom MembershipProvider class as transient (because it's using a service that's transient as well). This means that I want the Membership provider instance recreated on every web request. Currently, it is created only once per application domain so when it tries to access the service it depends on, that service instance is reused while it is

How do I control MembershipProvider instance creation/lifetime?

余生长醉 提交于 2019-12-17 13:04:04
问题 I have registered a custom MembershipProvider class in my Web.Config file. I'm using Inversion Of Control using Castle Windsor and I have registered my custom MembershipProvider class as transient (because it's using a service that's transient as well). This means that I want the Membership provider instance recreated on every web request. Currently, it is created only once per application domain so when it tries to access the service it depends on, that service instance is reused while it is

Castle Windsor Fluent API: Define Array with Single item as Dependency

妖精的绣舞 提交于 2019-12-14 02:28:19
问题 Given this XML configuration (which works) <component type="X.Y.Z.ActivityService, X.Y.Z.Services" id="X.Y.Z.ActivityService" lifestyle="transient"> <parameters> <Listeners> <array> <item>${DefaultActivityListener}</item> </array> </Listeners> </parameters> </component> <component type="X.Y.Z.DefaultActivityListener, X.Y.Z.Services" id="DefaultActivityListener" lifestyle="transient" /> I have converted to use the fluent API as below (which doesn't work): Container.Register( Component.For<X.Y

Convert Castle Windsor xml config to C# code

点点圈 提交于 2019-12-13 19:52:21
问题 I want to convert something like this: <components> <component id=""service1"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service1, MyAssembly""/> <component id=""service2"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service2, MyAssembly""/> <component id=""consumer"" type=""WindsorTests.Consumer, MyAssembly""> <parameters> <services> <dictionary> <entry key=""one"">${service1}</entry> <entry key=""two"">${service2}</entry> </dictionary> <