ioc-container

Resolving wrapper classes in C# with the Unity IoC container

I want to use Unity resolve IService to two different implementations, to make use of a wrapper class, the equivalent of: IService service = new DispatcherService(new RealService(), Application.Current.Dispatcher); Where both DispatcherService and RealService implement the IService interface. I have a library containing some service...

Why getting a 202 in two equal setup structuremap code paths

In the C# language, using StructureMap 2.5.4, targeting .NET Framework 3.5 libraries. I've taken the step to support multiple Profiles in a structure map DI setup, using ServiceLocator model with Bootstrapper activation. First setup was loading default registry, using the scanner. Now I like to determine runtime what Registry configur...

Unity to Structure Map

I am trying out the code from this post on Event Driven Architecture (very interesting by the way). His IOC container is Unity though and I would like to do this using Structure map. His code is: public class EventSubscriptions : ISubscriptionService { public static void Add<T>() { var consumerType = typeof(T); con...

Getting Spring IOC to work with the MVP pattern.

Im attempting to use the MVP design pattern with a Swing application in conjution with Spring IOC. In MVP the View needs to pass itself into the presenter, and I can't work out how to do this with Spring. public class MainView implements IMainView { private MainPresenter _presenter; public MainView() { _presenter = n...

Are IoC containers about configuration files?

Recently I developed a performance tester console application, with no UI, with the help of a IoC containter (Castle-Windsor-Microkernel). This library enabled me to let the user choose which test(s) to run, simply by changing the configuration file. Have I realized what IoC containers are about? I'm not sure. Even Joel said here on SO ...

Unity IOC Buildup vs Resolve?

I was wondering when do I use buildup and when do I use resolve, when using the Unity IOC. And when do I call teardown? Thanks ...

Register a single class for multiple closed versions of a generic interface in StructureMap using the scanner.

Here are the relevant types and an example of the handler I want linked to IHandle<EventA> and IHandle<EventB>: // marker interface public interface IEvent {} public interface IHandle<TEvent> where TEvent : IEvent { void Handle(TEvent e); } public class SomeHandler : IHandle<EventA>, IHandle<EventB> { public void Handle(EventA...

Injecting Dependencies into Domain Model classes with Nhibernate (ASP.NET MVC + IOC)

I'm building an ASP.NET MVC application that uses a DDD (Domain Driven Design) approach with database access handled by NHibernate. I have domain model class (Administrator) that I want to inject a dependency into via an IOC Container such as Castle Windsor, something like this: public class Administrator { public virtual int Id { g...

How to use/configure Unity Container IOC in my situation

Hi, I have some trouble implementing the Unity IOC into my project reading from config file. Here is what I have 1) ClasslibraryA 2) ClasslibraryB that references ClasslibraryA 3) Winforms App that references ClasslibraryB Note: SomeOther app will reference ClassLibraryA, eg. a web service. ClasslibraryA will have to be configured...

How to programmatically register a component that depends on a list of already registered components with Castle Windsor?

I'm programmatically registering a group of services that all implement the same interface, IRule. I have another service that looks like this: public class MyService { private IEnumerable<IRule> _rules; public MyService(IEnumerable<IRule> rules){ _rules = rules; } } Hammett posted something that looked like what ...

Castle and generics

Considering this code : interface IRepository<T> { void Save(); } class Repository<T> { public virtual void Save() // something { } } interface IOtherRepository : IRepository<OtherClass> { void Other(); } class OtherRepository : Repository<OtherClass>, IOtherRepository { public override void Save() // something d...

What is the correct layer to configure your IoC container when using a service layer?

I have a medium sized asp.net MVC app. It consumes a service layer that handles all the repository use, calling domain services, etc. My controller actions are very slim -- they basically call a service class, get a response and show that respose. Most components are interface based with some poor man's DI. The app is growing, needs ...

NHibernate Session DI from StructureMap in components

I know this is somewhat of a dead horse, but I'm not finding a satisfactory answer. First let me say, I am NOT dealing with a web app, otherwise managing NH Session is quite simple. I have a bunch of enterprise components. Those components have their own service layer that will act on multiple repositories. For example: Claim Compo...

Best Practice: How to get several dependency repositories into a ActionController?

I have a InventoryController that gets a IInventoryRepository inyected, however my needs have changed, and now one of the controllers methods also needs to use another 2 repositories, ILoansRepository (to see the get info about loaned inventory items) and another one, where some stats and extra info are found. The way it works is that a...

Using Ninject to inject dependencies into externally constructed objects (user control)

I would like to use Ninject in my WinForms application. I cannot figure out how to use it for my user controls. Sometimes they rely on the services I want to configure through the DI framework. These controls need to be manageable through the designer (thus need default constructors). So, is there a way to inject dependencies into pr...

Find class to instantiate by name without namespace or assembly? (.NET)

I'd like to instantiate a class by name (a string) without specifying a namespace or assembly. Like this (Unity syntax): var processor = container.Resolve<IProcessor>("SpecialProcessor"); would instantiate the first IProcessor it finds called SpecialProcessor. Maybe MyNamespace.SpecialProcessor I'd like to avoid having to create ...

StrcutureMap Wiring - Sanity Check Please

Hi - Im new to IOC and StructureMap and have an n-level application and am looking at how to setup the wirings (ForRequestedType ...) and just want to check with people with more experience that this is the best way of doing it! I dont want my UI application object to reference my persistence layer directly so am not able to wire everyt...

Specify constructor for the Unity IoC container to use

I'm using the Unity IoC container for resolving my objects. However, I've run into an issue. When I have more than one constructor - how does Unity know which one to use? It seems to use the one with parameters when I have one with and one without. Can I explicitly tell it which constructor to use? Specifically I had a case similar to ...

Convert Castle Windsor xml config to C# code

I want to convert something like this: <components> <component id=""service1"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service1, MyAssembly""/> <component id=""service2"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service2, MyAssembly""/> <component id=""consumer"" typ...

IoC.Resolve vs Constructor Injection

I heard a lot of people saying that it is a bad practice to use IoC.Resolve(), but I never heard a good reason why (if it's all about testing than you can just mock the container, and you're done). now the advantages of using Resolve instead of Constructor Injection is that you don't need to create classes that have 5 parameters in the...