ioc-container

how to get dependencies injected in constructors in Windows Forms

in asp.net-mvc I have the Windsor Controller Factory that injects all the dependencies into the controllers, but how do you get this in Windows Forms ? for example if have this Form1, how am I going to get an instance of Form1, should I use resolve (which is called ServiceLocator and anti-pattern by some ppl)? public class Form1 { ...

Comparing Castle Windsor, Unity and StructureMap

In a follow up to Krzysztof’s statement that Windsor does a lot more than other IoC’s, I wanted to understand how these IoC’s stack up against each other and the benefits/additional facilities that castle Windsor provides. Are there any comparisons? Can someone help me understand the additional features that Castle Windsor provides ov...

How to inject an asp.net 2.0 web service reference using ninject

I was trying to inject an asp.net 2.0 good old web service reference but it failed. the failure was when trying to use the injected interface. ...

Staying open with DI/IoC containers

I am involved with several open source projects which taken together provide an application development framework. The question I have is what mechanism(s) should I provide for integrating them with each other? On the conceptual level the answer is clear - DI/IoC. The "only" problem is to decide which one. In several installations we us...

Creating an instance using Ninject with additional parameters in the constructor

I decided to start using Ninject and face an issue. Say I have the following scenario. I have an IService interface and 2 classes implementing this interface. And also I have a class, which has a constructor getting IService and an int. How can I create an instance of this class with Ninject (I dont want to hardwire this int, I want to p...

Castle Windsor: Find an implementing assembly and used it.

How do I tell castle to pick up an interface implementation from the assemblies in the executing directory. E.g. How do I tell castle to find an implementation for ILog and then If I drop log4net among the assemblies in the executing directory, it should pick it and use it. Tomorrow if I decide to change log4net to Nlog it should pick...

Ninject kernel creation inside a class library

I have a class that has dependencies that I've wired up with Ninject. public interface IFoo {} public class MyObject { [Inject] IFoo myfoo; } In the real implementation I'm using property injection, but just to quickly illustrate, I'll inject on the field. As I understand, instead of newing instances of MyObject, in order ...

How do I use a Type Discriminator field in my DTO to instantiate the appropriate domain object with DI?

I am looking for suggestions on how to map a single DTO class with a type discriminator to multiple domain classes. I have my DTO: public class FooData { public Guid Id { get; set; } public string Name { get; set; } public string TypeDiscrim { get; set; } } public class FooDataRepository { public List<FooData> GetAll()...

Using Unity, How do I autoregister a generic class with a generic interface without registering EVERY type to it.

I am using Unity and Unity.AutoRegistration. This line for Unity: unityContainer.RegisterType(typeof(IAction<>), typeof(Action<>)); effectively registers every class in the project to IAction/Action: unityContainer.RegisterType<IAction<ObjectA>, Action<ObjectA>>(); unityContainer.RegisterType<IAction<ObjectB>, Action<ObjectB>>(); uni...

Immutable classes and unity application block

I am writing a small utility for myself so whilst I am using Unity currently, I can change to a different IoC container if it will allow me to get around this problem. I want to create a class that is given some data when it is created, but is immutable after that, normally I would do this with: class SomeItem { public SomeItem(str...

StructureMap: Configure concrete classes at run time?

I know that Concrete Types can be configured with Structure Map the following way: ForRequestedType<Rule>().TheDefault.Is.Object(new ColorRule("Green")); This works if you know the type ahead of time. I want to do it at run time, and there does not seem to be a way. Can some one enlighten me? What I want to do is something like the...

Can I use an IoC container to create a dependency that requires a runtime value?

I'm an IoC newbie, so I'm wondering if it's even the right tool for the job I want to do. I'm writing a multi-tenant application, and there are several places that we might want to use different implementations of interfaces based on the organization to which the currently logged-on user belongs. Say, for example, when a user from ...

Why are IOC containers unnecessary with dynamic languages

Someone on the Herding Code podcast No. 68, http://herdingcode.com/?p=231, stated that IOC containers had no place with Python or Javascript, or words to that effect. I'm assuming this is conventional wisdom and that it applies to all dynamic languages. Why? What is it about dynamic languages that makes IOC containers unnecessary? ...

IOC best practice: How to best manage dependency graph?

I am doing an MVC project with structuremap as an IOC container. We are doing TDD, and I want to set up my dependencies so that its easy to work with, and so that its easy to test. How should I best set up the graph of dependencies for the below fictional illustrated graph ? ApplicationController Controller AuthenticationService Us...

StructureMap - Instantiating properties for instance of interface x on concrete request

Hi! How do I wire structuremap to inject properties when builing instances of interface IDummy. Let's say that I have a concrete class called Dummy which implements interface IDummy. The Dummy class got two properties, the first one called DataContext implements IDataContext, the second property is just a basic string called MyDummySt...

Ninject modules or organising wiring up dependencies

I've started playing with Ninject and from a screencast it states the following is how you set up a binding: class MyModule : StandardModule { public override void Load() { Bind<IInterface>().To<ConcreteType>(); // More bindings here... } } This is all very good. However suppose you have one hundred objects u...

Multiple constructor with Structuremap changing the scope?

To illustrate the problem, here is a simplified version of my setup. I have a factory like this one : public interface IFactory{ } public class Factory : IFactory { public Factory() { Console.WriteLine("parameterless"); } //public Factory(int i) //{ // Console.WriteLine("with parameter : {0}", i); ...

Unity IOC container and how to resolve different instances of the same interface

I have a unity container that I am registering types within like so: IUnityContainer container = new UnityContainer() .RegisterType<ITaxAuthorityRateService, TaxAuthorityPopulationRateService>( "PopulationRate" ) .RegisterType<ITaxAuthorityRateService, TaxAuthorityBusinessLicenseRateService>( "BusinessLicenseRate" ); Then I also w...

Problem Implementing StructureMap in VB.Net Conversion of SharpArchitecture

I work in a VB.Net environment and have recently been tasked with creating an MVC environment to use as a base to work from. I decided to convert the latest SharpArchitecture release (Q3 2009) into VB, which on the whole has gone fine after a bit of hair pulling. I came across a problem with Castle Windsor where my custom repository inte...

Structuremap searching for scripts controller every page

I've configured structuremap successfully but every page search for a controller with name "scripts" public class StructureMapControllerFactory : DefaultControllerFactory { public override IController CreateController(RequestContext context, string controllerName) { Type controllerType = base.GetControll...