StructureMap Exception Code: 202 when opening Visitor Group tab within EPiServer 7

543 views Asked by At

I've created a visitor group and I'm trying to inject a class into it.I have the class all wired up and running fine in the site where I am injecting it into a block.

When I open the visitor group tab in the CMS, I get the following exception:

StructureMap Exception Code: 202 No Default Instance defined for 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

The code in the sites DependencyResolverInitialization module is:

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());
    });
} 

And the criterion is:

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;
    }
}

I suspect the issue is that the Modules area have their own StructureMap Container. Is this the case? And if so, how is the best way to make sure your mappings are carried through?

1

There are 1 answers

0
wałdis iljuczonok On

Maybe too late for the answer :) With Injected properties it's a bit more trickier. You have to tell EPiServer how that interface implementation is supposed to be created. This could be done using ServiceConfiguration attribute:

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