castle-windsor

NUnit integration tests and dependency injection

风格不统一 提交于 2019-12-30 09:00:08
问题 I'm currently making use of Castle Windsor version 2.1 as my container and would like to perform integration tests using the services registered with it. Currently, I do this my using the Common Service Locator to retrieve my service instance and perform my integration tests against it as such: var myService = ServiceLocator.Current.GetInstance<IMyService>(); // do stuff with myService What I'd ideally like to do is have my service dependencies injected into my NUnit test fixture

NUnit integration tests and dependency injection

*爱你&永不变心* 提交于 2019-12-30 09:00:03
问题 I'm currently making use of Castle Windsor version 2.1 as my container and would like to perform integration tests using the services registered with it. Currently, I do this my using the Common Service Locator to retrieve my service instance and perform my integration tests against it as such: var myService = ServiceLocator.Current.GetInstance<IMyService>(); // do stuff with myService What I'd ideally like to do is have my service dependencies injected into my NUnit test fixture

Inject ASP.NET MVC Controller property into service layer dependency?

柔情痞子 提交于 2019-12-30 03:18:09
问题 I am using an approach similar to the one in this ASP.NET MVC tutorial where you pass a wrapper around a controller's ModelState collection into a validation class so that the controller can access error information. Here is a cooked up example: interface IProductValidator { void Validate(Product item); } class ProductValidator { // constructor public ProductValidator(ModelStateWrapper validationDictionary) { } } interface IProductService { void AddProduct(); } public class ProductService :

IoC - Multiple implementations support for a single interface

非 Y 不嫁゛ 提交于 2019-12-30 01:51:06
问题 I am wondering why .Net IoC containers do not easily support multiple implementations for a single interface! May be I am wrong, but as far I have seen, frameworks like Ninject partially supports this feature using annotations (how?). I do not think other frameworks like Windsor or simple injector have an easy mechanism to support this scenario. Is there any reason why this is not supported by many frameworks? AFAIK, one of the most important reasons to use interfaces is to achieve loose

Multiple Interface injection with castle windsor

瘦欲@ 提交于 2019-12-30 00:39:10
问题 How can you get castle Windsor to choose the right implantation of a interface at run time when you have multiple implementations in the container. For example lets say i have a simple interface called IExamCalc that does calculations to work out how someone did in that exam. No we have several implementation of this like bellow for example, public interface IExamCalc { int CalculateMark(ExamAnswers examAnswers) } public class WritenExam : IExamCalc { public int CalculateMark(ExamAnswers

registering open generic decorators for typed implementations in castle windsor

那年仲夏 提交于 2019-12-29 09:24:22
问题 While trying to coerce Windsor into wrapping an implementation with a random number of decorators, i've stumbled upon the following: i have 3 decorators and an implementation all using the same interface. if you run this code, windsor resolves icommandhandler<stringcommand> as implementation , which, as far as i can tell, is expected behaviour, because the typed implementation can not be registered with the open typed decorators. However, if you uncomment the line container.Register(Component

Property injection in custom membership provider using Castle

给你一囗甜甜゛ 提交于 2019-12-29 09:04:25
问题 So far in reading about possibilities of injection to custom membership providers, I've found two possible ways to do it: One is the following: http://bugsquash.blogspot.com/2010/11/windsor-managed-membershipproviders.html Here the author basically suggests to register your custom provider and then have a rather questionable windsor adapter for membership (I don't really like the way in which it instances your provider using a container it gets from HttpApplication , which it ultimately wraps

logging in log4net to different appenders based on circumstances

折月煮酒 提交于 2019-12-29 06:50:12
问题 I am using log4net and in one class require logging to a RollingFile appender, but then in another class, I wish to log to the event log + rolling file + console appender. What is the best practice? and could I see some sample code? By the way to make things more difficult, I am using Castle Windsor Logging Facility with Log4net to resolve my Logger instance. If it helps, I was thinking this below, but have no idea if this is best practice, or how to activate a particular logger based on

Castle Windsor intercept method call from within the class

社会主义新天地 提交于 2019-12-29 06:31:52
问题 We have components registrations in Castle Windsor container like so void RegisterComponent<TInterface, TImplementation>() { var component = Component.For<TInterface>().ImplementedBy<TImplementation>(); component.Interceptors<SomeInterceptor>(); container.Register(component); } However we got to the problem that when we do a method call from within the class it does not get intercepted. For example we have component like ServiceA : IService { public void MethodA1() { // do some stuff } public

Castle Windsor - Injecting IActionInvoker Implementation Issue

回眸只為那壹抹淺笑 提交于 2019-12-29 05:34:13
问题 I am trying to use the approach from this article, but I am missing something - I am currently getting an error within WindsorControllerFactory.GetControllerInstance when it tries to resolve IActionInvoker since WindsorActionInvoker has a dependency on IWindsorContainer. Given that WindsorControllerFactory already has a reference to IWindsorContainer, could I pass that reference in? If so - how? The only examples I have found are about passing value types as constructor parameters, not