castle-windsor

Castle Windsor: How to test that all registered components are resolvable?

耗尽温柔 提交于 2019-12-03 16:04:55
I would like to write a test that just ensures that all components registered to my WindsorContainer can indeed be resolved. Anyone have any ideas how I can do that? See these posts from Bil Simser: http://weblogs.asp.net/bsimser/archive/2008/06/04/the-first-spec-you-should-write-when-using-castle.aspx http://weblogs.asp.net/bsimser/archive/2008/06/27/testing-castle-windsor-mappings-part-deux.aspx 来源: https://stackoverflow.com/questions/731616/castle-windsor-how-to-test-that-all-registered-components-are-resolvable

How to overwrite a component with castle windsor?

假装没事ソ 提交于 2019-12-03 15:37:18
问题 I want to redefine an (default) implementation in a given windsor-container. Is that what OverWrite is for? Doesn't work, though. container.Register( Component.For<IServiceOperationAuthorization>() .OverWrite() .Instance(_authorization) ); Any other Ideas? cheers, Lars 回答1: You could very simply do this in the place you need to override the default implementation. This is an example from our integration tests. Both implementations are now registered but your code will use the default one,

ASP.NET MVC, 'Ticket Required' Attribute

风格不统一 提交于 2019-12-03 14:40:55
I am attempting to build a system that allows users to perform certain actions, but their account must have a specific 'Ticket' per time they do it. For instance, suppose they wish to create a Product , they would need a CreateProductTicket . I could simply do this with some 'if' statements, sure, but I want to try a bit more of a robust solution. My structure looks something like this... interface ITicket<T> where T : ITicketable { } My basic goal is to build an Attribute, perhaps like the following.. public class TicketRequiredAttribute : Attribute { public TicketRequiredAttribute(ITicket<T>

Castle Windsor resolving and generics

假装没事ソ 提交于 2019-12-03 14:19:53
I have the following: public interface ISubject { ... } public class Subject<T> : ISubject { ... } public class MyCode<T> { ... pulic void MyMethod() { var item = container.Resolve<ISubject>(); //????? how do I pass in T } ... } In this case how do i do the resolve. Cheers Anthony vdhant - That's not how containers are meant to be used. You want to use ISubject , right?. Then if you passed T you're breaking your abstraction, because your caller must know that ISubject , is actually a Subject, and more than that, its a Subject<T> and that it requires a concrete T. No container will allow that,

How can I get Castle Windsor to automatically inject a property?

元气小坏坏 提交于 2019-12-03 14:14:23
I have a property on my classes for logging service. private ILogger logger = NullLogger.Instance; public ILogger Logger { get { return logger; } set { logger = value; } } And I have this in my component registration: container.AddFacility<LoggingFacility>(x => new LoggingFacility(LoggerImplementation.Log4net)); However, Windsor doesn't seem to inject the Logger - am I missing something? The lambda parameter for AddFacility is actually a creation callback (it gets called when the facility is created), not a factory. Use this instead: container.AddFacility("logging", new LoggingFacility

how to get dependencies injected in constructors in Windows Forms

怎甘沉沦 提交于 2019-12-03 12:36:42
问题 in asp.net-mvc I have the Windsor Controller Factory that injects all the dependencies into the controllers, but how do you get this in Windows Forms ? for example if have this Form1, how am I going to get an instance of Form1, should I use resolve (which is called ServiceLocator and anti-pattern by some ppl)? public class Form1 { private IBarService _barService; public Form1(IBarService barService) { _barService = barService; } } 回答1: Yes, in program.cs you should make windsor resolve Form1

Dependency Injection for Handlers and Filters in ASP.NET Web API

大兔子大兔子 提交于 2019-12-03 12:17:33
I am trying to wire up my Web Api project to use Castle Windsor for IoC I have done that for my controllers by following this excellent article . I am now trying to get dependencies injected into my DelegatingHandler and ActionFilterAttribute I have tried to copy the techniques used for filters in regular ASP.Net MVC but they don't seem to apply in Web Api has anyone managed to get this working? I'm not sure what the relevant extension point is in the Web Api I have seen this being suggested config.MessageHandlers.Add(_myContainer.Resolve<IApiUsageLogger>()); but not sure if there is a better

How can I get started with ASP.NET (5) Core and Castle Windsor for Dependency Injection?

风格不统一 提交于 2019-12-03 11:47:17
问题 Background: I've used Castle Windsor with Installers and Facilities according to the Castle Windsor tutorial with earlier versions of MVC (pre-6) and WebAPI. ASP.NET (5) Core has included some Dependency Injection support but I still haven't figured out exactly how to wire it up, and the few samples I have found look a lot different than how I've used it before (with the installers/facilities). Most examples predate ASP.NET (5) cores recent release and some seem to have outdated information.

What should be the strategy of unit testing when using IoC?

你。 提交于 2019-12-03 10:19:33
After all what I have read about Dependency Injection and IoC I have decided to try to use Windsor Container within our application (it's a 50K LOC multi-layer web app, so I hope it's not an overkill there). I have used a simple static class for wrapping the container and I initialize it when starting the app, which works quite fine for now. My question is about unit testing. I know that DI is going to make my life much easier there by giving me the possibility of injecting stub / mock implementations of class collaborators to the class under test. I have already written a couple of tests

Castle Windsor: is there a way of validating registration without a resolve call?

巧了我就是萌 提交于 2019-12-03 09:34:59
问题 My current understanding of Castle Windsor registration is that one can only validate registration by calling Resolve on a root component. But since windsor's component model knows each component's dependencies, it should be possible to test that all dependencies can be satisfied without actually instantiating anything. The main reason for wanting to do this is to have a unit test for registration that doesn't require me to stub components that call external resources on start-up. For example