ioc-container

How to Inject daoFactory into NHibernate EventListener

I need to Inject some global service (daoFactory) into EventListenet subscribed on PostUpdate event. I`ve read that it is possible to do this way: public class YourPostInsertListener : IPostInsertEventListener { private readonly IPersistentAuditor auditor; public YourPostInsertListener(IPersistentAuditor auditor) { this.auditor = a...

Spring.Net IoC and Magic Strings

I've been thinking about the IApplicationContext.GetObject(string name) method and it seems to rely fairly heavily on magic strings to get objects from the application context. With other containers like StructureMap you can use generics to specify the configuration and request objects but is there a better way than using strings with th...

Unity Container - Passing in T dynamically to the Resolve method

I've created an ISearchable interface that I've Typed so that I can retrieve an IEnumerable of T for the results. I have a number of services that implement ISearchable for different domain objects ... Container.RegisterType<ISearchable<Animal>, AnimalService>(); Container.RegisterType<ISearchable<Fish>, FishService>(); I...

Property Inject an Array with Spring.Net

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 pos...

.NET IoC - Equivalent Code for .NET Unity

In this Autofac IoC article they show an example of mapping an interface to an implementation with a parameter. You'll find it halfway down the article. What is the Unity equivalent in XML? Can't use the fluent syntax for what I'm doing. Needs to be an external config file. UPDATE: This is the specific piece of code I want to know how ...

Ninject, ASP.NET and Custom Controls

Hey guys, I'm currently using ASP.NET (standard, not MVC) and I'm using Ninject as my IOC container. I'm already using it to inject dependencies into my pages, however, I was wondering if there was a way to inject dependencies into my custom controls? If not, I'll get underway extending Ninject :) ...

linq2sql using with dependency injection?

Hi Does anyone know how to have dependency injection work with linq2sql. Heres my situation.. I will explain it as best i can here. I have a base class which has a DBML (linq2sql) and classes etc .. This DBML is COMMON to more than 1 project.. Well each project has its own DBML but has all the tables etc that is in the common dbml i a...

winsdor register a generic type with constructor parameter

i have somthing like this MyRepository<T> : IRepository<T> { public MyRepository(string cs){ .... } so i need to register in winsdor this generic type and give him a parameter i've been trying to do this like so : Type t = typeof(IRepository<>); Type t1 = typeof(Repository<>); Hashtable props = new Hashtable(); props.Ad...

Castle project per session lifestyle with ASP.NET MVC

Hello, I'm really new to Castle Windsor IoC container. I wanted to know if theres a way to store session variables using the IoC container. I was thinking something in the line of this: I want to have a class to store search options: public interface ISearchOptions{ public string Filter{get;set;} public string SortOrder{get;se...

Autofac, ASP.NET and Microsoft.Practices.ServiceLocation

I've been working thru the details of implementing IoC in my web apps but in a way that leverages Microsoft.Practices.ServiceLocation. I am specifically using Autofac and the asp.net integration, but I wanted to leave myself open to other containers. Along the lines of this question, i was concerned about how to access the container in m...

Castle Windsor: Constructor resolution order

Hi guys Just wondering how Castle Windsor determines which constructor to resolve when there are multiple constructors present. Cheers Anthony ...

Custom object factory extension for Unity

I am using the Unity IoC container, and I need to intercept any calls to Resolve for a certain base interface, and run my own custom code to construct those types. In other words, in the sample code below, when I call container.Resolve<IFooN>(), if it hasn't got an instance of the concrete implementing type, it calls MyFactoryFunction ...

DI Container: inject the right components from a collection of same types?

I'm trying to hack my own dependency injection container in PHP, based on constructor injection. The container instantiates complex objects and inject them with the required objects based on the type hints in the constructor using reflection. One thing I obviously stumbled upon is the fact that I can register multiple components that ca...

What is the equivalent of Container.GetAllInstances<T> in NInject?

I'm building a message broker with NInject, and I need to find all instances in the container that implement Consumes, an interface that marks the class as being able to consume a particular message type. Is this scenario supported? ...

Does ninject-contrib support Silverlight?

I'm building a Silverlight application with Prism, and we'd like to use NInject. I've downloaded ninject-contrib to use their NInject bootstrapper, but it doesn't appear to build a Silverlight assembly. I compiled it myself to Silverlight, but it crashes Visual Studio. Has anyone already ported ninject-contrib to Silverlight success...

Is ninject considered a container?

Hi, I was talking with someone and mentioned I was learning IOC and was using ninject to get the feel for things. He asked me what container I was using? I told him ninject. Having no idea what he was referring to, I know there is castle windsor products that are more popular. Can someone clear this up for me? What am I missing here...

How do you make a Ninject Provider when the constructor of type is not known?

I decided to try to conjure up a container assembly to interact with FubuMVC. Well the cool part is that it pass all the test that the FubuMVC.Container.StructureMap assembly does. However, when I dropped it into the FubuSample. I received an activation error. The error is because in the provider for the behaviors I'm only calling a par...

Windsor AddComponentInstance problem

I have successfully setup castle windsor using an xml configuration file and everything works fine. The only problem is that on a method I need Windsor to pass an existing instance to the constructor so I used container.Kernel.AddComponentInstance<IMyClass>(MyClassInstance); before the Resolve method but that does not work because Win...

Is Ninject MVC supposed to work with MVC 2 Preview?

I am running a MVC 2 Preview and this is my first time trying to use Ninject2 MVC There error that I am continently getting is: An error occurred when trying to create a controller of type 'MyMVC.Controllers.EventsController'. Make sure that the controller has a parameterless public constructor. What I have in my Global.cs is this: pu...

Unity to dispose of object

Is there a way to make Unit dispose property-injected objects as part of the Teardown? The background is that I am working on an application that uses ASP.NET MVC 2, Unity and WCF. We have written our own MVC controller factory that uses unity to instantiate the controller and WCF proxies are injected using the [Dependency] attribute on...