ICurrentMarket

Vote:
 

Hello everyone.

I'm currently running EPiServer Commerce 8.13.0 and I'm trying to implement my own ICurrentMarket module through the instructions here: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/8/Markets/Markets/

I have tried to copy this code:

[InitializableModule]
public class MyCurrentMarketModule : IConfigurableModule
{
    public void ConfigureContainer(ServiceConfigurationContext context)
    {
        context.Container.Configure(ce =>
        {
            ce.For().Singleton().Use();                
        });
    }

    public void Initialize(InitializationEngine context) { }
    public void Preload(string[] parameters) { }
    public void Uninitialize(InitializationEngine context) { }
}

But later when I run ServiceLocator.GetInstance(); an instance of CurrentMarketImpl is still returned and my market logics are not being used.

I found out this is because EPiServer registers CurrentMarketImpl as the implementation for ICurrentMarket AFTER I've registered my own. So structuremap returns the one registered last.

A workaround I have found is to configure the container in the

public void Initialize(InitializationEngine context)

method instead of the

public void ConfigureContainer(ServiceConfigurationContext context)

that will fire AFTER EPiServer has registered CurrentMarketImpl as the implementation for ICurrentMarket and therefore override it with my own logic.

But this does not feel like the right thing to do, there must be something else I've missed to done incorrectly?

Is there an option somewhere to enable multi market/disable CurrentMarketImpl that I've missed or what is wrong here? Is the documentation for ICurrentMarket incorrect?

#122562
Jun 05, 2015 10:42
Vote:
 

Hi,

You can add the module dependency like this:

[ModuleDependency(typeof(Mediachase.Commerce.Initialization.CommerceInitialization))]
    [InitializableModule]
    public class MyCurrentMarketModule

This will make sure your module runs after CommerceInitialization, then override the registration.
Regards.
/Q
#122563
Edited, Jun 05, 2015 11:06
Vote:
 

Thanks, this worked perfectly.

I suggest you add that line to the documentation i read here as well:

http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Commerce/8/Markets/Markets/

because that code does not work correctly without specifying that module dependency.

#122564
Jun 05, 2015 12:08
Vote:
 

Hi,

Thanks - that should be updated. I'll log a bug for that.

Regards.

/Q

#122565
Jun 05, 2015 12:29
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.