inversion-of-control

MVVM && IOC && Sub-ViewModels

I have a ViewModel, it takes two parameters in the constructor that are of the same type: public class CustomerComparerViewModel { public CustomerComparerViewModel(CustomerViewModel customerViewModel1, CustomerViewModel customerViewModel2) { } } public class CustomerViewModel { publ...

How to use NInject (or other DI / IoC container) with the model binder in ASP.NET MVC 2 ?

Let's say I have an User entity and I would want to set it's CreationTime property in the constructor to DateTime.Now. But being a unit test adopter I don't want to access DateTime.Now directly but use an ITimeProvider : public class User { public User(ITimeProvider timeProvider) { // ... this.CreationTime = timeProv...

How to manage IoC containers in tests?

I'm very new to testing and IoC containers and have two projects: MySite.Website (MVC) MySite.WebsiteTest Currently I have an IoC container in my website. Should I recreate another IoC container for my test? Or is there a way to use the IoC in both? ...

Unity and Object Creation

I am using unity as my IoC container. I am trying to implement a type of IProviderRepository. The concrete implementation has a constructor that accepts a type of IRepository. When I remove the constructor parameter from the concrete implementation everything works fine. I am sure the container is wired correctly. When I try to crea...

Where (layer) should DI be used?

Is there any layer where it is bad practice to use DI? In a previous question a user mentioned that DI should only be used in the UI layer. ...

IoC and dataContext disposing in asp.net mvc 2 application

I have the Global.asax like the code below: public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { // .... } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); ControllerBuilder...

How to get if the object is already retrieved in inject

Is it possible to know that particular dependency already has been satisfied by ninject kernel? To be clear: Let's suppose we have this module: Bind<IA>().To<A>(); Bind<IB>().To<B>(); And some "client"-code: var a = kernel.Get<IA>(); // how to get here "true" for assumption: "IA was requested (once)" // and "false" for: "IB was not...

Is dependency injection only for service type objects and singletons? (and NOT for gui?)

I'm currently experimenting with the Google's guice inversion of control container. I previously had singletons for just about any service (database, active directory) my application used. Now I refactored the code: all the dependencies are given as parameters to constructors. So far, so good. Now the hardest part is with the graphical u...

Multiple plugin instance loading with MEF

In my last application, using MEF to load plugins went just fine, but now I'm running into a new issue. I have a solution for it that I explain at the end of this question, but I'm looking for other ways to do it. Let's say I have an interface called ApplianceInterface. I also have two plugins that inherit from ApplianceInterface, let...

MEF's CompositionContainer.ComposeParts -- loading whatever can be resolved, and ignoring errors

The biggest problem I'm having so far with MEF is that when I compose parts in my plugin loader wrapper, loading completely bails when it finds an import resolution problem with one of the assemblies. Ideally, I'd like ComposeParts to exhibit some sort of "ignore and continue" behavior, because the ideal user experience would entail loa...

Dependency Injection, IoC and Mocking finally explained in a simple and understandable way!

I've been banging my head against the wall trying to understand these concepts for a week now. I was really surprised when I came across with a very understandable and simple explanations of these concepts in the ASP.NET MVC NerdDinner application tutorial. I suggest this to anyone struggling to have that 'aha' moment. http://nerddinner...

Using StructureMap, how do you explicitly trigger the reinstantiation of a object with InstanceScope.Singleton?

I have an integration test harness where I want to teardown and then re-instantiate some of the singleton-scoped objects I've registered with StructureMap, after and before each test. This way I can simulate the actual run time environment, but not have the singleton's state being passed from one test to another. Maybe this isn't a g...

Are MEF's ComposableParts contracts instance-based?

I didn't really know how to phrase the title of my questions, so my apologies in advance. I read through parts of the MEF documentation to try to find the answer to my question, but couldn't find it. I'm using ImportMany to allow MEF to create multiple instances of a specific plugin. That plugin Imports several parts, and within calls...

Problem Registering a Generic Repository with Windsor IoC

I’m fairly new to IoC and perhaps my understanding of generics and inheritance is not strong enough for what I’m trying to do. You might find this to be a mess. I have a generic Repository<TEntity> base class: public class Repository<TEntity> where TEntity : class, IEntity { private Table<TEntity> EntityTable; private st...

how to implement IOC without a global static service (non-service locator solution)?

Hi, we want to use Unity for IOC. All i've seen is the implementation that there is one global static service (let's call it the the IOCService) which holds a reference to the Unity container, which registers all interface/class combinations and every class asks that object: give me an implementation for Ithis or IThat. Frequently i se...

How to do resolving using Unity in a mutli-project solution

Hi everybody! In a new WPF project (VS2010) i 'm using Unity 2 for the first time. In this project i use the following structure: Solution WPF Project Class Library1 Class Library2 Class Library 3 .... Registering the different types using Unity is done in WPF Project using the following snippet: IUnityContainer container = new Un...

How to cascade dependency resolution w/ CDI (WELD)

I would like to have a central weld container that holds all my services and so on. This container would however be wrapped by a second container which contains local settings. The goal is if a dependency cannot be found in the outer container then I would like to then search the inner container. How can I achieve this? I would prefer t...

IOC Container that can target .NET Framework Client Profile?

On our current WPF project, we've been performing dependency injection using the Ninject IOC tool. We want to target the .NET Framework Client Profile for a better download/install experience. The problem is that Ninject seems to reference libararies such as System.Web which are NOT in the Client Profile. Can anyone recommend an IOC c...

Problem resolving a generic Repository with Entity Framework and Castle Windsor Container

Hi, im working in a generic repository implementarion with EF v4, the repository must be resolved by Windsor Container. First the interface public interface IRepository<T> { void Add(T entity); void Delete(T entity); T Find(int key) } Then a concrete class implements the interface public class Repository<T> : IR...

Add existing instance (object) to unity

Hi, i want to add an existing object to my unity container registered to a specific interface, so when i resolve the interface i get that existing object (it's used for testing, and the object holds a lot of XML data, and for eacht test case i want to use another object). I do it like this: public static void RegisterInstance<T>(T in...