Hi,
Please make sure two things:
- Your application is properly configured. You will need a web.config/app.config which point to Configs folder. Take a look at normal web.config file, which has references to various config files in /Configs folder
- You initialized FrameworkInitialization properly.
Regards.
/Q
Hi,
Here are my related configurations on my WCF web service web.config:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<sectionGroup name="FrameworkProviders">
<section name="dataService" type="Mediachase.Data.Provider.DataProviderSection, Mediachase.DataProvider" />
</sectionGroup>
<sectionGroup name="CommerceFramework">
<section name="Workflow" type="Mediachase.Commerce.WorkflowConfiguration,Mediachase.Commerce" />
<section name="Application" type="Mediachase.Commerce.Core.CoreConfiguration,Mediachase.Commerce" />
<section name="Catalog" type="Mediachase.Commerce.Catalog.CatalogConfiguration,Mediachase.Commerce" />
<section name="Marketing" type="Mediachase.Commerce.Marketing.MarketingConfiguration,Mediachase.Commerce" />
<section name="Orders" type="Mediachase.Commerce.Orders.OrderConfiguration,Mediachase.Commerce" />
<section name="Security" type="Mediachase.Commerce.Security.Configuration.SecurityConfigurationSection,Mediachase.Commerce" />
<section name="Customers" type="Mediachase.Commerce.Customers.Configuration.CustomerConfiguration,Mediachase.Commerce" />
<section name="ContentManagement" type="Mediachase.Cms.CmsConfiguration,Mediachase.Cms" />
<section name="AssetManagement" type="Mediachase.Commerce.Assets.AssetConfiguration, Mediachase.Commerce" />
</sectionGroup>
<sectionGroup name="mediachase.businessFoundation.data" type="Mediachase.BusinessFoundation.Data.Configuration.MediachaseDataSectionGroup, Mediachase.BusinessFoundation.Data">
<section name="metaClassManager" type="Mediachase.BusinessFoundation.Data.Meta.Management.Configuration.MetaClassManagerSection, Mediachase.BusinessFoundation.Data" />
<section name="metaObject" type="Mediachase.BusinessFoundation.Data.Meta.Configuration.MetaObjectSection, Mediachase.BusinessFoundation.Data" />
<section name="businessManager" type="Mediachase.BusinessFoundation.Data.Business.Configuration.BusinessManagerSection, Mediachase.BusinessFoundation.Data" />
</sectionGroup>
<sectionGroup name="Mediachase.BusinessFoundation">
<section name="BusinessFoundationSettings" type="Mediachase.BusinessFoundation.Configuration.BusinessFoundationConfigurationSection, Mediachase.BusinessFoundation" />
</sectionGroup>
<section name="episerver.framework" type="EPiServer.Framework.Configuration.EPiServerFrameworkSection, EPiServer.Framework" />
</configSections>
<!-- Business Foundation Configuration -->
<Mediachase.BusinessFoundation>
<BusinessFoundationSettings configSource="Configs\baf.config" />
</Mediachase.BusinessFoundation>
<mediachase.businessFoundation.data>
<businessManager configSource="Configs\baf.data.manager.config" />
<metaObject configSource="Configs\baf.data.metaobject.config" />
</mediachase.businessFoundation.data>
<!-- Framework configuration -->
<CommerceFramework>
<AssetManagement configSource="Configs\ecf.asset.config" />
<ContentManagement configSource="Configs\ecf.cms.config" />
<Workflow configSource="Configs\ecf.workflow.config" />
<Application configSource="Configs\ecf.app.config" />
<Catalog configSource="Configs\ecf.catalog.config" />
<Marketing configSource="Configs\ecf.marketing.config" />
<Orders configSource="Configs\ecf.order.config" />
<Customers configSource="Configs\ecf.customer.config" />
<Security configSource="Configs\ecf.security.config" />
</CommerceFramework>
<episerver.framework configSource="Configs\EPiServerFramework.config" />
<!-- Framework Providers -->
<FrameworkProviders>
<dataService defaultProvider="SqlDataProvider">
<providers>
<add name="SqlDataProvider" type="Mediachase.Data.Provider.SqlDataProvider, Mediachase.SqlDataProvider" connectionStringName="EcfSqlConnection" applicationName="EPiServerCommerceManager6" />
</providers>
</dataService>
</FrameworkProviders>
And here is the method I initialize the service locator with:
/// <summary>
/// Service locator initialization
/// </summary>
void InitializeServiceLocator()
{
var container = new StructureMap.Container();
var locator = new EPiServer.ServiceLocation.StructureMapServiceLocator(container);
var context = new EPiServer.ServiceLocation.ServiceConfigurationContext(HostType.Installer, container);
context.Container.Configure(ce =>
{
ce.For<IRequiredMetaFieldCollection>().Singleton().Use<NoRequiredMetaFields>();
ce.For<IWarehouseInventoryService>().Singleton().Use<CacheWarehouseInventoryService>()
.Ctor<IWarehouseInventoryService>().Is<Mediachase.Commerce.Inventory.Database.WarehouseInventoryServiceDatabase>()
.Ctor<TimeSpan>().Is(new TimeSpan(1, 0, 0));
ce.For<IWarehouseRepository>().Singleton().Use<Mediachase.Commerce.Inventory.Database.WarehouseRepositoryDatabase>();
ce.For<ISynchronizedObjectInstanceCache>().Singleton().Use<LocalCacheWrapper>();
ce.For<ICatalogSystem>().Singleton().Use(() => CatalogContext.Current);
ce.For<IChangeNotificationManager>().Singleton().Use<NullChangeNotificationManager>();
ce.For<IPriceService>().Singleton().Use<Mediachase.Commerce.Pricing.Database.PriceServiceDatabase>();
});
if (SqlContext.Current == null)
{
SqlContext.Current = new SqlContext(ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString);
}
if (DataContext.Current == null)
{
DataContext.Current = new DataContext(ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString);
}
EPiServer.ServiceLocation.ServiceLocator.SetLocator(locator);
}
With these configurations and initialization I can, for example, use OrderContext search methods without a problem to retrieve orders and manipulate them. But the CustomerContext I am baffled with and always end up with the "The type initializer for 'Mediachase.BusinessFoundation.Data.Meta.Management.TriggerManager' threw an exception."
Hi,
Your config looks right, nice work! Your initialization code should be changed a bit:
public class YourClass : InitializationEnigne
{
void
InitializeServiceLocator()
{
//your code
ConfigureContainer(HostType.Installer);
}
}
Let me know if it works for you :).
Regards.
/Q
Did you find the solution? I am also getting the same exception Mediachase.BusinessFoundation.Data.Meta.Management.TriggerManager threw an exception.
Hi,
I was able to resolve this issue by adding fake implementation for one of the interface
var container = new StructureMap.Container();
var locator = new StructureMapServiceLocator(container);
var context = new ServiceConfigurationContext(HostType.Service, container);
new Mediachase.Commerce.Initialization.CommerceInitialization().ConfigureContainer(context);
// Structure Map
context.Container.Configure(s =>
{
s.AddRegistry<InfrastructureRegistry>();
});
// Set EPiServer Locator service container to our defined structure map container
ServiceLocator.SetLocator(locator);
if (SqlContext.Current == null)
{
SqlContext.Current =
new SqlContext(ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString);
}
if (DataContext.Current == null)
{
DataContext.Current =
new DataContext(ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString);
}
in Infrastructure Regsitry
For<IMarketService>().HybridHttpOrThreadLocalScoped().Use<MarketServiceDatabase>();
For<IMarket>().HybridHttpOrThreadLocalScoped().Use<MarketImpl>();
For<ICurrentMarket>().HybridHttpOrThreadLocalScoped().Use<CurrentMarketImpl>();
For<ISynchronizedObjectInstanceCache>().HybridHttpOrThreadLocalScoped().Use<RemoteCacheSynchronization>();
For<IObjectInstanceCache>().HybridHttpOrThreadLocalScoped().Use<RemoteCacheSynchronization>();
For<ITypeScannerLookup>().HybridHttpOrThreadLocalScoped().Use<FakeTypeScannerLookup>();
I have same kind of issue but with a Quartz jobs, I tried to use your solution, but "InfrastructureRegistry" does not resolve for me. Which assembly does it live in?
Also I could not understand the Fake Implementation of an interface, would you mind sheding some light on it?
Hi Azhar,
Infrastructure is the below class which contains the dependency injection initialization
public class InfrastructureRegistry : Registry
{
public InfrastructureRegistry()
{
// Register your custom dependency below
For<IRequiredMetaFieldCollection>().Use<NoRequiredMetaFields>();
For<IMarketService>().HybridHttpOrThreadLocalScoped().Use<MarketServiceDatabase>();
For<IMarket>().HybridHttpOrThreadLocalScoped().Use<MarketImpl>();
For<ICurrentMarket>().HybridHttpOrThreadLocalScoped().Use<CurrentMarketImpl>();
For<ISynchronizedObjectInstanceCache>().HybridHttpOrThreadLocalScoped().Use<RemoteCacheSynchronization>();
For<IObjectInstanceCache>().HybridHttpOrThreadLocalScoped().Use<RemoteCacheSynchronization>();
For<ITypeScannerLookup>().HybridHttpOrThreadLocalScoped().Use<FakeTypeScannerLookup>();
/* ... My Other custom class registration goes here
* ....
*/
}
}
The TypeScannerLookup is internal class of EPiServer so you cant provide it in structure map registration. so therefore, i created fake implementation class for the ITypeScannerLookup interface of EPiServer.
I got the implementation of this class from original EPiServer TypeScannerLookup clas
/// <summary>
/// Default implementation of <see cref="T:EPiServer.Framework.TypeScanner.ITypeScannerLookup"/>
/// </summary>
public class FakeTypeScannerLookup : ITypeScannerLookup
{
private static object _lock = new object();
private HashSet<Type> _types = new HashSet<Type>();
/// <summary>
/// Gets the scanned types.
///
/// </summary>
public IEnumerable<Type> AllTypes
{
get
{
return (IEnumerable<Type>)this._types;
}
}
static FakeTypeScannerLookup()
{
}
/// <summary>
/// Adds the specified scanned type.
///
/// </summary>
/// <param name="t">The t.</param>
public void Add(Type t)
{
lock (_lock)
this._types.Add(t);
}
/// <summary>
/// Deletes the specified scanned type.
///
/// </summary>
/// <param name="t">The t.</param>
public void Delete(Type t)
{
this._types.Remove(t);
}
}
I had problems getting it up and running as well, so I took Niklas Israelssons's Commerce Integration Test Sample project on Github and made it into a Console app.
https://github.com/nicklasisraelsson/EPiCommerce.Integration.Sample
Im using EpiServer Commerce 7.5 and Im trying to retrieve organization information through CustomerContext method GetAllOrganization() in a WCF service application. However, when I try to call the method I get the following exception message:
"The type initializer for 'Mediachase.BusinessFoundation.Data.Meta.Management.TriggerManager' threw an exception."
"Activation error occurred while trying to get instance of type ITypeScannerLookup, key \"\""
"StructureMap Exception Code: 202\nNo Default Instance defined for PluginFamily EPiServer.Framework.TypeScanner.ITypeScannerLookup, EPiServer.Framework, Version=7.5.394.2, Culture=neutral, PublicKeyToken=8fe83dea738b45b7"
Stack:
I did some searching around the forum and made sure that I have initialized both SqlContext and DataContext before making the method call but this did not solve the problem. My guess it is an initialization problem but I am at loss what Im missing as I have copied my commerce config files and dll's to the bin folder plus the license file is at place.