'How can we add DI (Dependency Injection) of a class library to multiple projects in C# asp.net 6

Procuces Circular Dependency

here I am trying to add dependencies from SchoolAppASPv2.Infrastructure to SchoolAppASPv2.Identity but I am not being able to.

It shows an error in using SchoolAppASPv2.Infrastructure

using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using SchoolAppASPv2.Identity;
using SchoolAppASPv2.Identity.Data;
using SchoolAppASPv2.Identity.Models;
using SchoolAppASPv2.Identity.Services;
using SchoolAppASPv2.Infrastructure;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddInfrastructure(builder.Configuration);

builder.Services.AddControllers();


builder.Services.AddTransient<ILoginService<ApplicationUser>, EFLoginService>();


builder.Services.AddDbContext<ApplicationDbContext>(options => {
    options.UseSqlServer(
              builder.Configuration.GetConnectionString("SchoolAppAspConnection"),
              b =>             
b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName));

});

And This Being the Dependency Injection Class
The Dependency class has been used in 1 project but here I am trying to add it into another project. I am trying to connect the DbContext class of the SchoolAppASPv2.Infrastructure but I am being unable to add it

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SchoolAppASPv2.Application.Common.Interface;
using Microsoft.EntityFrameworkCore;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SchoolAppASPv2.Infrastructure.DataBase;
using SchoolAppASPv2.Infrastructure.Services;

namespace SchoolAppASPv2.Infrastructure
{
    public static class DependencyInjection
    {
    public static IServiceCollection AddInfrastructure(this IServiceCollection     
    services, IConfiguration configuration)
    {

        var connectionString =     
    configuration.GetConnectionString("SchoolAppAspConnection");

    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source