开发者

Resolve an Interface using Unity 2.1

开发者 https://www.devze.com 2023-03-26 04:16 出处:网络
I have a basic class that is trying to resolve an interface using Unity. IUnityContainer containter = new UnityContainer();

I have a basic class that is trying to resolve an interface using Unity.

            IUnityContainer containter = new UnityContainer();

            containter.RegisterType<IRepositoryFactory>();

            IRepositoryFactory repositoryFactory = containter.Resolve<IRepositoryFactory>();

My config file is as follows:

<unity>
    <containers>
        <container>
            <types>
                <type   name="IRepositoryFactory"
                        type="QuinntyneBrown.Interfaces.IRepositoryFactory"
                        mapTo="QuinntyneBrown.Photography.Factories.RepositoryFactory" />
            </types>
        </container>
    </containers>
</unity>

I'm getting the following error:

Resolution of the dependency failed, type = "QuinntyneBrown.Interfaces.IRepositoryFactory", name = "(none)". Exception occurred while: while resolving.

Exception is: InvalidOperationException - The current type, QuinntyneBrown.Interfaces.IRepositoryFactory, is an interface 开发者_如何学Goand cannot be constructed. Are you missing a type mapping?

At the time of the exception, the container was:

Resolving QuinntyneBrown.Interfaces.IRepositoryFactory,(none)


containter.RegisterType<IRepositoryFactory>();

This doesn't make any binding. Load bindings from your config file instead:

containter.LoadConfiguration();
0

精彩评论

暂无评论...
验证码 换一张
取 消