79702533

Date: 2025-07-15 18:47:28
Score: 0.5
Natty:
Report link

Why AddIdentityApiEndpoints<TUser>() is not available in the Infrastructure layer

When trying to use AddIdentityApiEndpoints<TUser>() in the Infrastructure layer, you might encounter errors because this method is specifically designed for Minimal APIs in .NET 8 and is not accessible from class libraries like Infrastructure. In other side, you may notice that you can access to AddIdentityCore<TUser>() or AddIdentity<TUser>() methods with only the package Microsoft.AspNetCore.Identity.EntityFrameworkCore installed in your Domain or Infrastructrue layer.

Why does this happen?

Solution

To maintain a clean architecture, you should:

  1. In the Infrastructure layer, configure Identity Core and Entity Framework.

    services.AddIdentityCore<IdentityUser>().AddEntityFrameworkStores<ApplicationDbContext>();

  2. In your project web Api layer, configure the API endpoints (via AddIdentityApiEndpoints).

    builder.Services.AddIdentityApiEndpoints<IdentityUser>();

Conclusion

This maintains a clean and modular architecture.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Whyis not
  • Low reputation (1):
Posted by: A.SOW