Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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)
// want to register dbContext here with so that I can use it like mentioned in section 2
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<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.
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...
Write your reply to:
Image will be uploaded when post is submitted