ioc-container

Castle Windsor - how to resolve components based on constructor parameters

ぃ、小莉子 提交于 2019-12-05 19:23:53
问题 Say I have a component like this public class MyComponent { public MyComponent(string name) { } } I basically want to have the provided constructor parameters behave as part of the component identifier when resolving it. If you've never resolved it with that set of parameters, it will instantiate a new one. In other words, I want to somehow modify the following test to succeed: IWindsorContainer container = new WindsorContainer(); container.Register(Component.For<MyComponent>()); MyComponent

Using StructureMap, is one of these project organizations better than another?

﹥>﹥吖頭↗ 提交于 2019-12-05 17:38:19
I'm starting to work with StructureMap on a windows application project. In working on learning the basics, I found 2 ways to arrange my solution that accomplish the same goal, and I'm wondering if anyone can comment on if one of these 2 seems like a better option, and why. The goal here was to use IOC so that I could use 2 services without taking dependencies on them. So I I created interfaces in my Business Layer, and then implemented those interfaces in my Infrastructure project and wrapped the actual services at that point. In my fist attempt at this, I created a project DependencyResolver

Simple Injector Register All Services From Namespace

空扰寡人 提交于 2019-12-05 17:22:07
问题 My Service Interfaces has a namespace of Services.Interfaces The implementation of the Service Interfaces has a namespace of Web.UI.Services I have 2 service implementations for example IUserService which needs to register to UserService ICountryService which needs to register to CountryService This is how I currently register these services with SimpleInjector. container.Register<IUserService, UserService> (); container.Register<ICountryService, CountryService> (); Problem: If I have over

Register string value for concrete name of parameter

六月ゝ 毕业季﹏ 提交于 2019-12-05 15:33:06
I am using Autofac and I have several classes which ask for parameter of type string and name lang. Is there a way to register a string value to all parameters named "lang", so it resolves automatically? I do not want to edit any of the constructors, since it is not my code (I know accepting e.g. CultureInfo would make registration easy..) Something resulting in short syntax like builder.Register(lang => "en-US").As().Named("lang") would be ideal. Thank you. A fairly simple way to solve this is with a custom Autofac module. First, implement the module and handle the IComponentRegistration

How to turn this Service Locator pattern into true Dependency Injection pattern?

强颜欢笑 提交于 2019-12-05 13:37:30
I asked a more general question a minute ago: How to organize DI Framework usage in an application? , and the feedback I got was that I was using a Service Locator Pattern rather than true DI as is pointed out by Martin Fowler here: http://martinfowler.com/articles/injection.html Actually, I read that article just the other day, but apparently haven't quite grasped it. So let's say I have the following code: interface ICardReader { string GetInfo(); void SetDebugMode(bool value); void Initialize(string accountToken); void ShowAmount(string amount); void Close(); ICreditCardInfo GetCardInfo();

Property Inject an Array with Spring.Net

淺唱寂寞╮ 提交于 2019-12-05 12:35:44
I've been using the Spring.Net IoC container and can use it to inject properties that are of type IList and even IList<T> but I'm a bit stumped as to how to inject a property thats of type string[] . There doesn't seem to be an <array> element defined in the XSD's and using <list> <value> </list> doesn't work either. If anyone could post the xml I need to inject using an array for a property it'd be much appreciated As mentioned here in the documentation you can inject a string array as a comma delimited string (not sure what the syntax is for escaping actual commas in strings if necessary).

Error when using DependencyResolver for Controller instantiation with MVC 3

守給你的承諾、 提交于 2019-12-05 11:50:52
I'm using MVC 3 and using the following code when the application starts... UnityContainer container = new UnityContainer(); new UnityMappings(container); DependencyResolver.SetResolver(new UnityServiceLocator(container)); Now when the app runs I'm getting the following error (but only sometimes)... Activation error occured while trying to get instance of type IControllerFactory, key "" Interestingly, if I continue with the web request, the website works normally. Any ideas? I can't see what I'm doing differently from before when this worked fine. Cheers, Ian. MVC3 requests a lot more than

Spring JUnit4 manual-/auto-wiring dilemma

此生再无相见时 提交于 2019-12-05 11:41:12
I ran into an issue that can only be explained with my fundamental lack of understanding of Spring's IoC container facilities and context setup, so I would ask for clarification regarding this. Just for reference, an application I am maintaing has the following stack of technologies: Java 1.6 Spring 2.5.6 RichFaces 3.3.1-GA UI Spring framework is used for bean management with Spring JDBC module used for DAO support Maven is used as build manager JUnit 4.4 is now introduced as test engine I am retroactively (sic!) writing JUnit tests for the application and what suprised me is that I wasn't

Is it possible to use Dependency Injection with xUnit?

ぐ巨炮叔叔 提交于 2019-12-05 09:48:21
问题 I have a test class with a constructor that needs an IService. public class ConsumerTests { private readonly IService _service; public ConsumerTests(IService servie) { _service = service; } [Fact] public void Should_() { //use _service } } I want to plugin my DI container of choice to build the test class . Is this possible with xUnit ? 回答1: Yes there is now, these two questions and answers should be consolidated in my opinion, see answer here Net Core: Execute All Dependency Injection in

How to change dependency registration at run time using simple injector?

戏子无情 提交于 2019-12-05 09:37:51
I'm using the Simple Injector IoC framework, and I would like to be able to change the dependency registration at run time. For example, I have two implementations, A and B , of interface I . Implementation A is registered at app start, but depending on some flag which can change during runtime, I would like to switch the implementation. We are currently doing this the OnActionExecuting event of our BaseController , which all of our controllers inherit from. Here is the sample code of what I am trying to do. protected override void OnActionExecuting( ActionExecutingContext filterContext) { if