简体   繁体   中英

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. It was implemented with Microsoft.Extensions.Configuration.Json package.

This existing project has a lot of useful functions and I do not want to rebuild them in my new project("Project B"). Hence I tried to add Project A to Project B as DLL file.

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. Basically the DLL does not read the configuration of Project B even though I tried the exactly same Json file structure.

Question

  1. Is it recommended at all to add reference of Project A into Project B as DLL?

  2. If yes, then how should I handle configurations like DB connections, and other parameters which Project A requires?

Probably best to extend "Project A" and have things like your DB connection in "Project B" ported into "Project A". It seems like right now the system is checking the config in "Project A" only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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