Using GlassMapper 4, Sitecore 8.2 update 3 and Microsoft DI
How do I register the GlassMapper SitecoreService in my Ioc. It requires a Database and Im not entirely clear on how to get that inside my method for registering items in my Ioc:
public class DependencyInjection : IServicesConfigurator
{
public void Configure(IServiceCollection serviceCollection)
{
var serviceProvider = serviceCollection.BuildServiceProvider();
serviceCollection.AddTransient<ISitecoreContext>(provider => new SitecoreContext());
serviceCollection.AddTransient<IGlassHtml>(provider => new GlassHtml(serviceProvider.GetService<ISitecoreContext>()));
serviceCollection.AddTransient<IControllerSitecoreContext>(provider => new ControllerSitecoreContext(serviceProvider.GetService<IGlassHtml>()));
serviceCollection.AddTransient<ISitecoreService>(provider => new SitecoreService(serviceProvider.GetService<ISitecoreContext>().Database));
serviceCollection.AddGlassMaps("DD.Data*");
serviceCollection.AddMvcControllers("DD.Web*");
}
}
This does not work. The database item in null at this point.