Unity 1.2 Dependency injection of internal types

Posted by qvin on Stack Overflow See other posts from Stack Overflow or by qvin
Published on 2010-06-09T23:01:45Z Indexed on 2010/06/09 23:12 UTC
Read the original article Hit count: 245

I have a facade in a library that exposes some complex functionality through a simple interface. My question is how do I do dependency injection for the internal types used in the facade. Let's say my C# library code looks like -

public class XYZfacade:IFacade
{
    [Dependency]
    internal IType1 type1
    {
        get;
        set;
    }
    [Dependency]
    internal IType2 type2
    {
        get;
        set;
    }
    public string SomeFunction()
    {
        return type1.someString();
    }
}

internal class TypeA
{
....
}
internal class TypeB
{
....
}

And my website code is like -

 IUnityContainer container = new UnityContainer();
 container.RegisterType<IType1, TypeA>();
 container.RegisterType<IType2, TypeB>();
 container.RegisterType<IFacade, XYZFacade>();
 ...
 ...
 IFacade facade = container.Resolve<IFacade>();

Here facade.SomeFunction() throws an exception because facade.type1 and facade.type2 are null. Any help is appreciated.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about dependency-injection