Base solution for your next web application
Open Closed

IocManager.Instace Integration Test - Container null - Cannot resolve Dependency Injection #10857


User avatar
0
[email protected] created

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? 8.9.1
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? Net Core

I am trying to do an Integration Unit Tes, but it is not possible because in some places of the codes use IocManager.Instance.

For example.

In this case the container is null, and it cannot resolve the dependency injection for some services.

Could you please validate if it is ok, or I would need to change something?

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    musa.demir created

    Hi @[email protected]

    If your test inherits AppTestBase or AbpIntegratedTestBase you can use Resolve<T>. Just like https://github.com/aspnetzero/aspnet-zero-core/blob/7ccc77e1c574eff37e0e7a30b774caa2f1c367a6/aspnet-core/test/MyCompanyName.AbpZeroTemplate.Tests/MultiTenancy/TenantAppService_Tests.cs#L25

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    For a better testable code, we don't suggest using IocManager.Instance, see the bottom of https://aspnetboilerplate.com/Pages/Documents/Dependency-Injection#iiocresolver-iiocmanager-and-iscopediocresolver.

    You can try injecting IIocManager and use it instead for resolving IBusinessRule.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    [email protected] created

    perfect! thanks!

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)