StructureMap异常代码:202无默认实例PluginFamily定义 [英] StructureMap Exception Code: 202 No Default Instance defined for PluginFamily

查看:1136
本文介绍了StructureMap异常代码:202无默认实例PluginFamily定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来StructureMap。我已经下载并使用版本2.6.1.0上午
。我不断收到以下
错误:




StructureMap异常代码:202 $ B $没有定义
默认实例b PluginFamily
Company.ProjectCore.Core.IConfiguration,
Company.ProjectCore,版本= 1.0.0.0,
区域性=中性公钥=空




我的Global.asax.cs如下:

 保护无效的Application_Start(对象发件人,EventArgs五)
{

变种集装箱=新容器(X =>
{
x.For< ICACHE>()使用<高速缓存> ();
x.For&所述; IEmailService>()使用<。EmailService>();
x.For&所述; IUserSession>()使用<。UserSession>();
x.For&下; IRedirector>()使用<。重定向>();
x.For&所述; INavigation>()使用<导航和GT;();
});

container.AssertConfigurationIsValid();

}



我从ObjectFactory.Initialize改为新容器来调试。
当通过AssertConfigurationIsValid()方法步进,缓存
的作品,但EmailService在了
的GetInstance方法失败下面一行:

  [可插拔(默认)] 
公共类EmailService:IEmailService

私人只读IConfiguration _configuration;

公共EmailService()
{
_configuration = ObjectFactory.GetInstance< IConfiguration>();
}

如果我删除IEmailService,同样的202错误是在IUserSession抛出。

我应该添加别的东西的Application_Start还是在我的类文件?



谢谢...


解决方案

此问题已修复与<$ C $替换 ObjectFactory.Initialize C> ObjectFactory.Configure 并添加组件在我的项目:

  ObjectFactory.Configure(X = > 
{
x.Scan(扫描=>
{
scan.LookForRegistries();
scan.Assembly(MyAssembly程序);
scan.Assembly(MyAssembly程序);
});
});


I am new to StructureMap. I have downloaded and am using version 2.6.1.0. I keep getting the below error:

StructureMap Exception Code: 202 No Default Instance defined for PluginFamily Company.ProjectCore.Core.IConfiguration, Company.ProjectCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

My Global.asax.cs looks like:

protected void Application_Start(object sender, EventArgs e)
{

    var container = new Container(x =>
                    {
                        x.For<ICache>().Use<Cache>();
                        x.For<IEmailService>().Use<EmailService>();
                        x.For<IUserSession>().Use<UserSession>();
                        x.For<IRedirector>().Use<Redirector>();
                        x.For<INavigation>().Use<Navigation>();
                    });

                container.AssertConfigurationIsValid();

}

I changed from ObjectFactory.Initialize to "new Container" to debug. When stepping through the AssertConfigurationIsValid() method, Cache works but EmailService fails at the GetInstance method in the following line:

[Pluggable("Default")]
public class EmailService : IEmailService

private readonly IConfiguration _configuration;

public EmailService()
{
    _configuration = ObjectFactory.GetInstance<IConfiguration>();
}

If I remove IEmailService, the same 202 error is thrown at IUserSession.

Should I be adding something else in Application_Start or in my class files?

Thanks in advance...

解决方案

This problem was fixed by replacing ObjectFactory.Initialize with ObjectFactory.Configure and adding the assemblies in my project:

ObjectFactory.Configure(x =>
{
    x.Scan(scan =>
    {
        scan.LookForRegistries();
        scan.Assembly("MyAssembly");
        scan.Assembly("MyAssembly");
    });
});

这篇关于StructureMap异常代码:202无默认实例PluginFamily定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆