Try our conversational search powered by Generative AI!

ModuleDependency use of ContentLanguage

Vote:
 

Hi,

In my class with InitializableModule attribute I need to use ContentLanguage.PreferredCulture.Name.

My dependency is: 

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]

Error:

No default Instance is registered and cannot be automatically determined for type 'EPiServer.DataAbstraction.ILanguageBranchRepository'

There is no configuration specified for EPiServer.DataAbstraction.ILanguageBranchRepository

1.) Container.GetInstance(EPiServer.DataAbstraction.ILanguageBranchRepository)

Any idea what other dependency to use, or other idea to get ContentLanguage to work at this stage.

Thanks!

#141667
Nov 18, 2015 8:56
Vote:
 

Hi,

All ServiceLocator dependencies are registired in EPiServer.ServiceLocation.ServiceContainerInitialization module which is executed very early (this is one of the first InitializableModule).

It looks like the EPiServer.Web.InitializationModule is the latest executed EPiServer module. So I think that your ModuleDependency is correct.

I tried to use ContentLanguage.PreferredCulture.Name inside module on the Alloy site and it's working.

Do you using any other dependencies resolved through ServiceLocator? Are they working?

#141696
Nov 18, 2015 20:38
Vote:
 

Hi,

ServiceLocator is working in our project, yes.

I am setting our DependencyResolver depending on language. Here is the class:

  [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
  [InitializableModule]
  public class DependencyResolverInitialization : IConfigurableModule
  {
    public void ConfigureContainer(ServiceConfigurationContext context)
    {
      context.Container.Configure(ConfigureContainer);

      DependencyResolver.SetResolver(new StructureMapDependencyResolver(context.Container));
    }

    private static void ConfigureContainer(ConfigurationExpression container)
    {
      //Swap out the default ContentRenderer for our custom
      container.For<IContentRenderer>().Use<ErrorHandlingContentRenderer>();
      container.For<ContentAreaRenderer>().Use<ContentAreaRenderer>();


//Use  ContentLanguage.PreferredCulture.Name here.

    }

    public void Initialize(InitializationEngine context)
    {
    }

    public void Uninitialize(InitializationEngine context)
    {
    }

    public void Preload(string[] parameters)
    {
    }



Above, ContentLanguage does not work in ConfigureContainer function. Other examples I have seen the class inherited from IInitializableModule. But if I do, I can't get context.Container.

#141735
Edited, Nov 19, 2015 10:05
Vote:
 

I think that when you configure container through IConfigurableModule you should use some "earlier" module dependency like:

[ModuleDependency(typeof(EPiServer.Shell.ShellInitialization))]


but I'm not sure if it's related with your problem

#141739
Nov 19, 2015 10:21
Vote:
 

That didn't work. 

"ConfigureContainer is called on all IInitializableModule before initialization begins. This allows modification of the container before service instances are created during initialization."

At this stage It seems like I can't work with ServiceLocator at all. 

#141744
Nov 19, 2015 10:50
* 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.