This article describes an issue with the ServiceConfigurationContext.Container method after having upgraded to Episerver 10+. The API will throw the following error.
Error CS0619
'ServiceConfigurationContext.Container' is obsolete: 'Access StructureMap using extension method StructureMap() available in NuGet package EPiServer.ServiceLocation.StructureMap'
The discussion on this issue can be seen in our documentation.
New NuGet package for StructureMap integration
A new NuGet package EPiServer.ServiceLocation.StructureMap will be introduced which will contain the integration with StructureMap, with support both for the existing signed StructureMap 3 and the new unsigned StructureMap 4 which we currently cannot support. The package only contain the integration and have NuGet dependencies on the official StructureMap packages. Episerver and module packages should not directly depend on this package but use our own abstractions for dealing with dependency injection, this API have been available for a few versions now and is already being used by most Episerver products.
This change makes it easier to support multiple versions of StructureMap but we are also looking into the dependency injection system that is shipped with .NET Core. Moving the dependency to a NuGet package is the same approach we have for logging, where we have abstractions in the platform and an integration in a separate NuGet package.
You might have noticed that we obsoleted the "Container" property in the initialization system and move that logic into an extension method, that was a preparation for this change where the extension method will be provided by a separate NuGet package (since EPiServer.Framework will no longer have any direct dependencies on StructureMap).
The original code would look like the following.
void IConfigurableModule.ConfigureContainer(ServiceConfigurationContext context) { context.Container.Configure(x => x.For().Use()); }
The new code would look something like this.
context.StructureMap().Configure(c =>
{
c.For<IService>().Use<Service>();
});
The recommendation is to update the obsoleted code to resolve this error.
Please sign in to leave a comment.