我正在构建Blazor WASM应用程序。
该应用程序正在运行,但是我现在希望将项目拆分为明智的自包含项目,但是在解决如何实现依赖项注入而不在项目之间创建循环依赖项时遇到问题。
Projects:
App.Client - UI Razor Pages
App.Server - Main project, controllers, defines interfaces
App.Shared - Shared models between Client & Server
App.Data - Implements repositories, unit of work, Db Context, migrations
我遇到的问题是App.Data项目具有对App.Server项目的依赖关系,以实现其所需的接口,但是我不确定如何在以下位置中配置startup.cs文件中的依赖关系: App.Server项目,因为它不能依赖App.Data项目。
答案 0 :(得分:0)
Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Test.Models;
using Test.Models.Data;
namespace Test
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
...
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("database"), b => b.MigrationsAssembly("Test")));
services.AddIdentity<User, Role>()
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IAntiforgery antiforgery)
{
...
}
}
}
项目结构
答案 1 :(得分:0)