在EPiServer 7中打开访客组选项卡时,StructureMap例外代码:202

时间:2013-09-05 15:13:07

标签: episerver episerver-7

我已经创建了一个访问者组,我正在尝试将一个类注入其中。我将所有类都连接起来并在我将其注入块中的网站中正常运行。

当我在CMS中打开访问者组标签时,出现以下异常:

  

StructureMap异常代码:202没有定义默认实例   PluginFamily   EPiServer.ServiceLocation.ServiceAccessor`1 [Bennetts.Site.Community.Membership.IMemberFactory,   Bennetts.Site.Community,Version = 1.0.0.0,Culture = neutral,   PublicKeyToken = null]],EPiServer.Framework,Version = 7.0.859.16,   Culture = neutral,PublicKeyToken = 8fe83dea738b45b7

站点DependencyResolverInitialization模块中的代码是:

public void ConfigureContainer(ServiceConfigurationContext context)
{
    .......

    context.Container.Configure(x =>
    {
        x.For<IMemberFactory>()
            .Use<MemberFactory>()
            .Ctor<string>("serviceHostname")
            .Is(i => i.GetInstance<IConfigurationSettings>().GetExternalCmsServiceHostname())
            .Ctor<int>("ServicePort")
            .Is(i => i.GetInstance<IConfigurationSettings>().GetExternalCmsServicePort());
    });
} 

标准是:

public class IsMemberCriterion : CriterionBase<IsMemberCriterionSettings>
{
    public Injected<IMemberFactory> MemberFactory { get; set; }

    public override bool IsMatch(IPrincipal principal, HttpContextBase httpContext)
    {
        return MemberFactory.Service.GetMember(principal.Identity.Name) != null;
    }
}

我怀疑问题是模块区域有自己的StructureMap容器​​。是这样的吗?如果是这样,那么确保映射的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

答案可能为时已晚:) 使用Injected属性会更棘手。您必须告诉EPiServer应该如何创建该接口实现。这可以使用ServiceConfiguration属性:

来完成
[ServiceConfiguration(Lifecycle = ServiceInstanceScope.Unique, ServiceType = typeof(IMemberFactory))]
public class DefaultMemberFactory : IMemberFactory
{
}