开发者

Structure map .Ignore a type while verifying the container

I am getting this error while verifying my Structuremap configuration using container.AssertConfigurationIsValid() in my UnitTes开发者_StackOverflow中文版t.

No Default Instance defined for PluginFamily MyComp.IMeasureRepository.

Infact for this particular Interface i dont have any plans for dependency injection.So can we make the Stucturemap ignore this Interface and still pass my UnitTest.


Something else that is registered with StructureMap likely takes an IMeasureRepository as a dependency. StructureMap needs to know how to satisfy that dependency.


I figure the interface is registered as part of a scan and not as a ctor argument. While scanning you can selectively include or exclude assemblies, namespaces and types.

You should be able to use ExcludeType<IMeasureRepository>() in the scanning configuration.

Example:

ObjectFactory.Initialize(c =>
    {
        c.Scan(scan =>
            {
                scan.TheCallingAssembly();
                scan.WithDefaultConventions();
                scan.ExcludeType<IMeasureRepository>();
            });
    });

See the Scan documentation for further details.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜