2

I built my own serviceProviderBuilder using StructureMap and replaced the default one from Sitecore.

public class StructureMapServiceProviderBuilder : BaseServiceProviderBuilder
{
    protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection)
    {
        var container = new Container();
        container.Populate(serviceCollection);
        return container.GetInstance<IServiceProvider>();
    }
}

In Sitecore logs I see the following error from StructureMap (complaining about BaseAuthenticationManager):

Exception: StructureMap.Building.StructureMapBuildException
Message: Bi-directional dependency relationship detected!
Check the StructureMap stacktrace below:
1.) Container.GetInstance(Sitecore.Abstractions.BaseAuthenticationManager)
2.) Lambda: Invoke(value(StructureMap.ContainerExtensions+<>c__DisplayClass9_0).descriptor.ImplementationFactory, IContext.GetInstance())
3.) Instance of Sitecore.Owin.Authentication.Configuration.FederatedAuthenticationConfiguration (System.Object)
4.) new AuthenticationManager(*Default of BaseCacheManager*, *Default of BaseTicketManager*, *Default of ProviderHelper<AuthenticationProvider, AuthenticationProviderCollection>*, *Default of AuthenticationSourceResolver*, *Default of AuthenticationTypeResolver*, *Default of FederatedAuthenticationConfiguration*, *Default of ApplicationUserFactory*, *Default of UserFactory*, *Default of ExternalLogoutManager*)
5.) Sitecore.Owin.Authentication.Security.AuthenticationManager
6.) Instance of Sitecore.Owin.Authentication.Security.AuthenticationManager
7.) Container.GetInstance(Sitecore.Owin.Authentication.Security.AuthenticationManager)
8.) Container.TryGetInstance(Sitecore.Owin.Authentication.Security.AuthenticationManager)
9.) Lambda: Invoke(value(StructureMap.ContainerExtensions+<>c__DisplayClass9_0).descriptor.ImplementationFactory, IContext.GetInstance())
10.) Instance of Sitecore.Abstractions.BaseAuthenticationManager (System.Object)
11.) Container.GetInstance(Sitecore.Abstractions.BaseAuthenticationManager)

Source: Anonymously Hosted DynamicMethods Assembly
    at lambda_method(Closure , IBuildSession , IContext )
    at StructureMap.Building.BuildPlan.Build(IBuildSession session, IContext context) in C:\BuildAgent\work\a395dbde6b793293\src\StructureMap.Shared\Building\BuildPlan.cs:line 152
    at StructureMap.Pipeline.LifecycleObjectCache.Get(Type pluginType, Instance instance, IBuildSession session) in C:\BuildAgent\work\a395dbde6b793293\src\StructureMap.Shared\Pipeline\LifecycleObjectCache.cs:line 71
    at StructureMap.SessionCache.GetObject(Type pluginType, Instance instance, ILifecycle lifecycle) in C:\BuildAgent\work\a395dbde6b793293\src\StructureMap.Shared\SessionCache.cs:line 93
    at StructureMap.SessionCache.GetDefault(Type pluginType, IPipelineGraph pipelineGraph) in C:\BuildAgent\work\a395dbde6b793293\src\StructureMap.Shared\SessionCache.cs:line 68
    at StructureMap.Container.GetInstance(Type pluginType) in C:\BuildAgent\work\a395dbde6b793293\src\StructureMap.Shared\Container.cs:line 720
    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
    at Sitecore.DependencyInjection.LazyResetable`1.get_Value()
    at Sitecore.Context.ContextData.get_User()
    at Sitecore.Security.AccessControl.ItemAccess.CanRead()
    at Sitecore.Data.Managers.ItemProvider.ApplySecurity(Item item, SecurityCheck securityCheck)
    at Sitecore.ContentTesting.Pipelines.ItemProvider.GetItem.GetItemUnderTestProcessor.Process(GetItemArgs args)
    at (Object , Object )
    at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
    at Sitecore.Data.Managers.DefaultItemManager.GetItem(String itemPath, Language language, Version version, Database database, SecurityCheck securityCheck)
    at Sitecore.Data.Managers.DefaultItemManager.GetItem(String itemPath, Language language, Version version, Database database)
    at Sitecore.Data.Managers.ItemManager.GetItem(String itemPath, Language language, Version version, Database database)
    at Sitecore.Globalization.DictionaryDomain.GetDomainDefinitionItem(Database database, String name)
    at Sitecore.Globalization.DictionaryDomain.TryParse(String domainDefinition, Database database, DictionaryDomain& domain)
    at Sitecore.Globalization.DictionaryDomain.GetDefaultDomain(Database database)
    at Sitecore.Pipelines.GetTranslation.TryGetFromContextDatabase.Process(GetTranslationArgs args)
    at (Object , Object )
    at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
    at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
    at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, Boolean failIfNotExists)
    at Sitecore.Globalization.DefaultTranslate.TextByLanguage(String domainName, TranslateOptions options, String key, Language language, String defaultValue, Object[] parameters)
    at Sitecore.Globalization.DefaultTranslate.TextByLanguage(String key, Language language, String defaultValue, Object[] parameters)
    at Sitecore.Globalization.Translate.TextByLanguage(String key, Language language, String defaultValue, Object[] parameters)
    at Sitecore.Abstractions.BaseJobStatus.LogInfo(String message, Object[] args)
    at (Object , Object )
    at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
    at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
    at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
    at Sitecore.Jobs.DefaultJob.DoExecute()
    at Sitecore.Abstractions.BaseJob.ThreadEntry(Object state)

Do you know any extra configuration which should be done to make it work with StructureMap?

1 Answer 1

1

I had setup Autofac on a solution as the default sitecore ioc container, however we ran into the same issue when using the forms module as described in this post: Autofac.Core.DependencyResolutionException Sitecore 9.2. Might be good to verify if StructureMap is fully supported by sitecore.

I tried setting up quickly StructureMap on my 9.2 installation using the code you posted, however I am getting the following error:

ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: BaseRepository<TEntity> must have at least one public constructor to be plugged in by StructureMap]
   StructureMap.Pipeline.ConstructorInstance`1..ctor(Type concreteType) +590
   StructureMap.ContainerExtensions.Register(IProfileRegistry registry, ServiceDescriptor descriptor) +88
   StructureMap.ContainerExtensions.Register(IProfileRegistry registry, IEnumerable`1 descriptors) +93
   StructureMap.ContainerExtensions.Populate(ConfigurationExpression config, IEnumerable`1 descriptors)
1
  • 1
    I don't have an official answer from Sitecore, but based on your answer and my experience it's not fully supported. We ended up switching back to the default IoC container. Commented Apr 14, 2021 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.