Structuremap and generic types

女生的网名这么多〃 提交于 2019-12-05 15:33:46

That's actually the more straightforward use of generics.

For(typeof(IMyClass<>)).Use(typeof(MyClass<>))

If you are using an older version of Structuremap, substitute the more verbose ForRequestType and TheDefaultIsConcreteType.

After some searching, I found out that you can use the auto register feature on Structuremap 2.5+ with generics over conventions, just like you could do with non-generics.

Just create your container like:

return new Container(x =>
        {
            x.Scan(y =>
            {
                y.TheCallingAssembly();
                y.AddAllTypesOf(typeof(IMyClass<>));
                y.WithDefaultConventions();
            });
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!