【发布时间】:2022-01-16 05:06:57
【问题描述】:
早上好。
我正在使用 Net 6 开发 Web API。
API的初步结构如图所示。
ContractGpdApi - 这是 API 的直接组装。它引用了 ContractGpdApi.ServiceInterfaces 程序集。 ContractGpdApi.ServiceInterfaces - 此程序集包含 DTO 类(业务模型)和服务接口。 ContractGpdApi.ServiceImplementations - 此程序集包含实现 ContractGpdApi.ServiceInterfaces 程序集接口的类。该程序集将 ContractGpdApi.DbServiceInterfaces 程序集的方法和类改编为 ContractGpdApi.ServiceInterfaces 程序集的方法和类。 ContractGpdApi.DbServiceInterfaces - 此程序集包含类和数据库访问层接口。 ContractGpdApi.DbServiceImplementations - 此程序集包含实现 ContractGpdApi.DbServiceInterfaces 程序集接口的类。该程序集包含对 ContractGpdApi.DbServiceInterfaces 程序集的引用,以及对 microsoft.entityframeworkcore、microsoft.entityframeworkcore.sqlserver 程序集的引用
我最终实现了梯形图模式并将 CUI 划分为松散耦合的层。
DB 层由两个程序集表示:ContractGpdApi.DbServiceImplementations 和 ContractGpdApi.DbServiceInterfaces。
业务工作层由两个程序集表示:ContractGpdApi.ServiceImplementations 和 ContractGpdApi.ServiceInterfaces。
因此,程序集 ContractGpdApi 将是一种根,您可以在其中加载和嵌入依赖项,松散链接的程序集。
加载程序集时出现以下错误:
- 无法加载文件或程序集“ContractGpdApi.DbServiceInterfaces,版本=1.0.0.0,文化=中性,PublicKeyToken=null”。找不到指定的文件。
- 无法加载文件或程序集“Microsoft.EntityFrameworkCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”。找不到指定的文件。
所有其他程序集都正常加载。 ContractGpdApi.csproj 文件内容:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ContractGpdApi.ServiceInterfaces\ContractGpdApi.ServiceInterfaces.csproj" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="call F:\CopyingAssemblies.bat" />
</Target>
</Project>
CopyingAssemblies.bat 文件的内容:
xcopy /y "C:\Git\ContractGpdApi\ContractGpdApi.DbServiceImplementations\bin\Debug\net6.0\*.dll" "C:\Git\ContractGpdApi\ContractGpdApi\bin\Debug\net6.0"
xcopy /y "C:\Git\ContractGpdApi\ContractGpdApi.ServiceImplementations\bin\Debug\net6.0\*.dll" "C:\Git\ContractGpdApi\ContractGpdApi\bin\Debug\net6.0"
告诉我,我做错了什么?
【问题讨论】:
-
您可能希望使用
.net-assembly标签而不是assembly。请阅读assembly标签的描述。
标签: c# .net api .net-assembly