Try our conversational search powered by Generative AI!

StructureMap Exception Code: 202 when opening Visitor Group tab

Vote:
 

Hi,

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?

Thanks

#74735
Sep 05, 2013 17:08
Vote:
 

Maybe too late for the answer :)
With Injected<T> 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
{
}

    

#84538
Apr 03, 2014 9:52
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.