I want to use the Microsoft.EntityFrameworkCore.dbContext into the controller.
I would really appreciate if I can get to know how we can register dependency for that in:
public class Global : UmbracoApplication, IComposer
{
public void Compose(Composition composition)
{
composition.Register<IRepository1, Repository1>();
// want to register dbContext here with so that I can use it like mentioned in section 2
}
Section2
public class Repository1 : IRepository1
{
private SomeDbContext _context;
public Repository1(SomeDbContext dbContext)
{
_context = dbContext;
}
}
That should not be that difficult. Give it a try with:
composition.Register(typeof(SomeDbContext));
or
composition.Register<SomeDbContext>(factory => new SomeDbContext(), Lifetime.Scope);
in your component.
Instead of implementing the IComposer interface you should implement the IUserComposer interface.
It is good to know that Umbraco 8 uses LightInject for DI, so you can search the www for specific scenarios with LightInject.
https://www.lightinject.net/
Register dbContext through composition
I want to use the Microsoft.EntityFrameworkCore.dbContext into the controller.
I would really appreciate if I can get to know how we can register dependency for that in:
Section2
Hi kapil,
That should not be that difficult. Give it a try with:
or
in your component.
Instead of implementing the
IComposer
interface you should implement theIUserComposer
interface.It is good to know that Umbraco 8 uses LightInject for DI, so you can search the www for specific scenarios with LightInject. https://www.lightinject.net/
You can also take a look at https://github.com/umbraco/Umbraco-CMS/blob/977bf91409a7965519c0504228cc68b11c6ca5c6/src/Umbraco.Web/Runtime/WebInitialComposer.cs to see different ways you can register stuff.
Thanks for your reply Corne. factory option worked with the combination of passing new dbContextOption builder
is working on a reply...