ioc-container

LightInject IoC container throws stackoverflow when resolving type

北城以北 提交于 2019-12-10 13:45:36
问题 When trying out the LightInject IoC container http://www.lightinject.net/ it throws a stackoverflow exception when resolving the type ISomeService: All types are registered in App_Start: container.RegisterAssembly("MyApp*.dll"); And then when I try to resolve it in the controller it fails and throws a stackoverflow exception: public SomeController(ISomeService someService) { _someService = someService; } It also has the same error when using ServiceLocator: ServiceLocator.Current.GetInstance

Ninject 2.0 - binding to a object that uses the same interface more than once?

最后都变了- 提交于 2019-12-10 13:37:20
问题 Consider the following: public Something(IInterface concreteObjectOne, IInterface concreteObjectTwo) { this.concreteObjectOne = concreteObjectOne; this.concreteObjectTwo = concreteObjectTwo; } How do I set set this type of binding up with Ninject? I'd try Googling the term, but as I'm not sure what this is called I can't, nor can I find anything on the Wiki about this. Edit : I believe this is called Convention Based Binding, as described here. However this documentation is for version 1.0

Is there a simple way to register static closures with Castle Windsor?

别等时光非礼了梦想. 提交于 2019-12-10 13:22:35
问题 I've been experimenting with using named delegates instead of single-method interfaces. This has some advantages for code size, as we can go from (some linebreaks removed so as not to overstate the case): public interface IProductSource { IEnumerable<Product> GetProducts(); } public class DataContextProductSource : IProductSource { private readonly DataContext _DataContext; public DataContextProductSource(DataContext dataContext) { if (dataContext == null) throw new ArgumentNullException(

What is the IServiceLocator interface?

孤者浪人 提交于 2019-12-10 13:05:54
问题 From what I understand IServiceLocator is an interface to abstract the actual IoC container away? I'm asking with relation to Prism where I'm trying to replace Unity with Prism, and I see Prism-classes relying on IServiceLocator. Could someone please clarify the role of the interface and when it is used? And also; what is the Common Service Locator, and will this be helpful when working with IServiceLocator? 回答1: IServiceLocator is an abstraction of a service locator. IoC containers are kind

When is a Transient-scope object Deactivated in Ninject?

北城以北 提交于 2019-12-10 13:02:07
问题 When an object in Ninject is bound with InTransientScope() , the object isn't placed into the cache, since it's, er, transient and not scoped to anything. When done with the object, I can call kernel.Release(obj) ; this passes through to the Cache where it retrieves the cached item and calls Pipeline.Deactivate using the cached entry. But since transient objects aren't cached, this doesn't happen. I haven't been able to figure out where (or who) performs the deactivation for transient objects

How to register same class twice with different dependencies

人盡茶涼 提交于 2019-12-10 12:30:32
问题 I would like to configure Castle Windsor to create two components of same type (Foo -> IFoo), but with different constructor inputs. I would also later like to consume both components when creating another component (type Bar - see code below). public interface IFoo { } public class Foo : IFoo { private string _prop; public Foo(string prop) { _prop = prop; } } public class Bar { private IFoo _fooAbc; private IFoo _foo123; public Bar(IFoo fooAbc, IFoo foo123) { _foo123 = foo123; _fooAbc =

How should I use IoC DI with this repository pattern?

谁说胖子不能爱 提交于 2019-12-10 10:44:12
问题 I am using the repository pattern found in the answer to this SO question: Advantage of creating a generic repository vs. specific repository for each object? Namely, each repository inherits from an abstract base class that contains generic methods like add, delete, etc. and also implements a specific repository interface for any methods that are unique to that repository/entity. ie. public class CompanyRepository : Repository<Company>, ICompanyRepository { ... } In my business layer I am

Passing parameters to UsingFactoryMethod in Castle Windsor

霸气de小男生 提交于 2019-12-10 09:56:46
问题 How do I pass dynamic parameters to a UsingFactoryMethod registration? For example, I want to write something like: container.Register( Component.For<IFoo>() .UsingFactoryMethod(return DoSomethingAndReturnInstance(paremeter))); I need the parameters to be sent at runtime, like this: container.Resolve<IFoo>(new { parameter = value }); How can it be done? 回答1: CreationContext.AdditionalParameters has the values you pass to Resolve 回答2: You just have to use container.Register( Component.For<IFoo

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

╄→гoц情女王★ 提交于 2019-12-10 09:23:48
问题 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

Spring JUnit4 manual-/auto-wiring dilemma

给你一囗甜甜゛ 提交于 2019-12-10 05:24:34
问题 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