castle-windsor

Windsor LifeStyle - Shared instance per Graph

北城余情 提交于 2019-11-28 02:15:31
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 : IService {} container.Register(Component.For<IService>() .ImplementedBy<Service >().LifeStyle.Transient);

Func<T> injecting with Windsor container

房东的猫 提交于 2019-11-28 01:29:27
问题 Here is a code excerpt from AspComet project that works with Autofac. public MessageBus(IClientRepository clientRepository, Func<IMessagesProcessor> messagesProcessorFactoryMethod) { this.clientRepository = clientRepository; this.messagesProcessorFactoryMethod = messagesProcessorFactoryMethod; } How can I inject " Func<IMessagesProcessor> messagesProcessorFactoryMethod " with Windsor, is it possible? Thanks. 回答1: container.Register(Component.For<Func<Foo>>().Instance(f)); Here's a passing

Castle, AOP and Logging in .NET

泪湿孤枕 提交于 2019-11-28 00:35:45
问题 Are there any tutorials or sample programs out there on using AOP, Castle, and logging in a .Net application? I have found pieces out there but I am looking for something more to help me form a more complete picture. Thanks, -Brian 回答1: You need to be using a custom Interceptor, which inherits from IInterceptor. For example: public class LogInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { Logger.Write("I'm in your method logging your access"); invocation.Proceed();

Castle Windsor IOC: Passing constructor parameters to child components

微笑、不失礼 提交于 2019-11-27 23:13:02
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. But the above code is not working, saying that dataService expecting dependancy which was not satisified.

How do I use Windsor to inject dependencies into ActionFilterAttributes

别说谁变了你拦得住时间么 提交于 2019-11-27 20:47:24
问题 Having seen how NInject can do it and AutoFac can do it I'm trying to figure out how to inject dependencies into MVC ActionFilters using Castle Windsor At the moment I'm using an ugly static IoC helper class to resolve dependencies from the constructor code like this: public class MyFilterAttribute : ActionFilterAttribute { private readonly IUserRepository _userRepository; public MyFilterAttribute() : this(IoC.Resolve<IUserRepository>()) { } public MyFilterAttribute(IUserRepository

IoC: Castle Windsor and WebAPI

廉价感情. 提交于 2019-11-27 20:08:07
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 that I'm reading up on WebAPI, I'm told DI will not work so well using Castle Windsor, talking about

Castle Windsor - How to map Named instance in constructor injection

谁都会走 提交于 2019-11-27 16:15:20
问题 maybe this is easy, but searching it on the internet already give me a head ache here is the problem: interface IValidator { void Validate(object obj); } public class ValidatorA : IValidator { public void Validate(object obj) { } } public class ValidatorB : IValidator { public void Validate(object obj) { } } interface IClassA { } interface IClassB { } public class MyBaseClass { protected IValidator validator; public void Validate() { validator.Validate(this); } } public class ClassA :

Using Entity Framework with Castle Windsor

三世轮回 提交于 2019-11-27 15:40:10
问题 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

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

风流意气都作罢 提交于 2019-11-27 15:37:27
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 IArticleRepository articleRepository; public ValidateUniqueUrlNodeAttribute(string message) { this

In Castle Windsor 3, override an existing component registration in a unit test

回眸只為那壹抹淺笑 提交于 2019-11-27 15:36:54
问题 I am attempting to use Castle Windsor in my automated tests like so: On every test: The Setup() function creates a Windsor container, registering default implementations of each component The Test function access the components via the method IWindsorContainer.Resolve<T> , and tests their behavior The TearDown() function disposes of the Windsor container (and any created components) For example, I might have 15 tests which accesses components which indirectly results in the creation of an