Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Per Nergård 3 posts 73 karma points notactivated
    Mar 25, 2024 @ 07:46
    Per NergÄrd
    0

    Umbraco AddUmbracoDbContext works in controller but context is null when injected into service class

    Hi

    I'm building a Umbraco 13 solution which where Umbraco will be the backend and have a REACT frontend.

    We are migrating a existing web-app so I have hooked up that database with EF Core and so far so good.

    builder.Services.AddUmbracoDbContext<dbContext>(
    

    My rough architecure is that I will have a lot of WEB API controllers that in turn will use service-classes that I will hook up with DI for simple reuse between in the different services or other BE use.

    So the EF DB I have got connected with using the AddUmbracoDbContext to the WebbApp builder services and using that context in the controllers work just fine.

    But when I inject the dbContext in my service it's null but working perfectly fine in the api-controller.

    So if someone could give me some pointers to what I need to do in order to get my EF dbContext to work with DI in my services I would be very grateful!

Please Sign in or register to post replies

Write your reply to:

Draft