Skip to content

Instantly share code, notes, and snippets.

@markgibbons25
Last active October 6, 2019 03:03
Show Gist options
  • Save markgibbons25/ab3fa332b5048adbcc8cec30a7c7aedf to your computer and use it in GitHub Desktop.
Save markgibbons25/ab3fa332b5048adbcc8cec30a7c7aedf to your computer and use it in GitHub Desktop.
public class RegisterDependencies : Sitecore.DependencyInjection.BaseServiceProviderBuilder
{
protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection)
{
// FIX FOR https://github.com/aspnet/AspNetCore/issues/2737
var options = new ServiceProviderOptions();
var type = options.GetType();
var propertyInfo = type.GetProperty("Mode", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
propertyInfo.SetValue(options, 1); // SET TO RUNTIME
return serviceCollection.BuildServiceProvider(options);
}
}
Patch as follows:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<serviceProviderBuilder>
<patch:attribute name="type" value="Foundation.DependencyInjection.DI.RegisterDependencies, Foundation.DependencyInjection" />
</serviceProviderBuilder>
</sitecore>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment