简体   繁体   English

C#-使用配置将参考项目导入为DLL

[英]C# - Import reference project as DLL with configuration

Background 背景

I have an existing project ("Project A") which has config files set up as JSON files. 我有一个现有项目(“ Project A”),该项目的配置文件设置为JSON文件。 It was implemented with Microsoft.Extensions.Configuration.Json package. 它是通过Microsoft.Extensions.Configuration.Json包实现的。

This existing project has a lot of useful functions and I do not want to rebuild them in my new project("Project B"). 这个现有的项目有很多有用的功能,我不想在我的新项目(“ Project B”)中重建它们。 Hence I tried to add Project A to Project B as DLL file. 因此,我试图将Project A作为DLL文件添加到ProjectB。

Problem 问题

After adding the reference, it seems the configuration setup in Project B has become difficult to handle, things like DB connections etc. Those were configured in Project A and passed into functions in Project A using dependency injection. 添加引用之后,似乎项目B中的配置设置已变得难以处理,例如DB连接等。这些已在项目A中进行配置,并使用依赖项注入传递给项目A中的功能。 Basically the DLL does not read the configuration of Project B even though I tried the exactly same Json file structure. 基本上,即使我尝试了完全相同的Json文件结构,DLL也不会读取Project B的配置。

Question

  1. Is it recommended at all to add reference of Project A into Project B as DLL? 是否建议将项目A的引用作为DLL添加到项目B中?

  2. If yes, then how should I handle configurations like DB connections, and other parameters which Project A requires? 如果是,那么我应该如何处理数据库连接等配置以及Project A所需的其他参数?

Probably best to extend "Project A" and have things like your DB connection in "Project B" ported into "Project A". 最好扩展“项目A”,并将“项目B”中的数据库连接移植到“项目A”中。 It seems like right now the system is checking the config in "Project A" only. 现在看来,系统仅在“ Project A”中检查配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM