当前位置:网站首页>Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
Should I have a separate interface assembly- Should I have a separate assembly for interfaces?
2022-07-02 12:57:00 【Bustling city 】
problem :
We currently have quite a few classes in a project, and each of those classes implement an interface, mostly for DI reasons. We currently have quite a few classes in a project , Each class implements an interface , Mainly out of DI Why .
Now, my personal feeling is that these interfaces should be put into a separate namespace within the same assembly (so we have a MyCompany.CoolApp.DataAccess
assembly, and within that there's an Interfaces
namespace giving MyCompany.CoolApp.DataAccess.Interfaces
). Now? , My personal feeling is that , These interfaces should be placed in a separate namespace in the same assembly ( So we have a MyCompany.CoolApp.DataAccess
Assembly , And one of them Interfaces
Namespace given MyCompany.CoolApp.DataAccess.Interfaces
).
However, somebody has suggested that these interfaces should actually be in their own assembly. however , It is suggested that these interfaces should actually be in their own assemblies .And my question is - are they right? My question is - Are they right ?I can see that there are some benefits (eg. other projects will only need to consume the interface assembly), but at the end of they day all of these assemblies are going to need to be loaded. I can see some benefits ( for example , Other projects only need to use interface assemblies ), But eventually all these assemblies need to be loaded .It also seems to me that there could be a slightly more complex deployment issue, as Visual Studio will not automatically pull the implementing assembly into the target's bin folder. in my opinion , The deployment problem may be a little more complicated , because Visual Studio The implementation assembly will not be automatically pulled into the target bin Folder .
Are there best practice guidelines for this? Is there a best practice guide ?
EDIT: edit :
To make my point a little clearer: We already separate UI, DataAccess, DataModel and other things into different assemblies. Let me make my point clearer : We have already UI、DataAccess、DataModel And other things are divided into different assemblies .We can also currently swap out our implementation with a different implementation without any pain, as we map the implementing class to the interface using Unity (IOC framework). At present, we can also replace our implementation with a different implementation without any pain , Because we use Unity(IOC frame ) Map implementation classes to interfaces .I should point out that we never write two implementations of the same interface, except for reasons of polymorphism and creating mocks for unit testing. I should point out , We never write two implementations of the same interface , Unless it's out of polymorphism and for unit testing The reason for building simulation .So we don't currently "swap out" an implementation except in unit tests. therefore , In addition to unit testing , We won't at present “ Swap out ” An implementation .
The only downside I see of having the interface in the same assembly as the implementation is that the whole assembly (including the unused implementation) will have been loaded. I think the only disadvantage of putting interfaces and implementations in the same assembly is the entire assembly ( Including unused implementations ) Will be loaded .
I can, however, see the point that having them in a different assembly means that developers won't accidentally "new" the implementing class rather than have it created using the IOC wrapper. however , I can see that putting them in different assemblies means that developers will not be surprised “ newly build ” Implementation class , Instead of using IOC The wrapper creates it .
One point I haven't understood from the answers is the deployment issue. What I don't understand from the answer is the deployment problem .If I am just depending on the interface assemblies, I'll have a something like the following structure: If I just rely on interface assemblies , I will have something similar to the following structure :
MyCompany.MyApplication.WebUI References: MyCompany.MyApplication.Controllers.Interfaces MyCompany.MyApplication.Bindings.Interfaces etc...
When I build this, the assemblies that are automatically put into the bin folder are just those interface assemblies. When I build this , Auto put bin The assemblies in the folder are just those interface assemblies .However, my type mappings in unity map different interfaces to their actual implementations. however , I am here unity The type mapping in maps different interfaces to their actual implementation .How do the assemblies that contain my implementations end up in the bin folder? How does the assembly containing my implementation end up in bin In the folder ?
Solution :
Reference resources : https://stackoom.com/en/question/E6wy边栏推荐
- . Net, C # basic knowledge
- C modifier
- To bypass obregistercallbacks, you need to drive the signature method
- bellman-ford AcWing 853. Shortest path with side limit
- LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
- 哈希表 AcWing 841. 字符串哈希
- Linear DP acwing 895 Longest ascending subsequence
- Bom Dom
- [ybtoj advanced training guidance] cross the river [BFS]
- Browser storage scheme
猜你喜欢
How can attribute mapping of entity classes be without it?
bellman-ford AcWing 853. 有边数限制的最短路
模块化 CommonJS ES Module
Heap acwing 839 Simulated reactor
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
阿里发布的Redis开发文档,涵盖了所有的redis操作
线性DP AcWing 902. 最短编辑距离
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
8 examples of using date commands
C modifier
随机推荐
Get started REPORT | today, talk about the microservice architecture currently used by Tencent
8A 同步降压稳压器 TPS568230RJER_规格信息
[200 opencv routines] 100 Adaptive local noise reduction filter
JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
包管理工具
Typora+docsify quick start
JS iterator generator asynchronous code processing promise+ generator - > await/async
哈希表 AcWing 840. 模拟散列表
Shutter encapsulated button
传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
Hash table acwing 841 String hash
接口测试面试题目,你都会了吗?
. Net, C # basic knowledge
Linear DP acwing 902 Shortest editing distance
spfa AcWing 851. spfa求最短路
Counting class DP acwing 900 Integer partition
js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
堆 AcWing 838. 堆排序
Mobile layout (flow layout)
架构师必须了解的 5 种最佳软件架构模式