当前位置:网站首页>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边栏推荐
- Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
- JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
- Enhance network security of kubernetes with cilium
- 3 A VTT端接 稳压器 NCP51200MNTXG资料
- Execute any method of any class through reflection
- 线性DP AcWing 899. 编辑距离
- Oracle from entry to mastery (4th Edition)
- Direct control PTZ PTZ PTZ PTZ camera debugging (c)
- js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
- Apply lnk306gn-tl converter, non isolated power supply
猜你喜欢

JSON serialization and parsing

C operator

JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)

BOM DOM
![[ybtoj advanced training guidance] cross the river [BFS]](/img/4e/83f14452ea6410768cdd01e725af2e.jpg)
[ybtoj advanced training guidance] cross the river [BFS]

Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
![[opencv learning] [image histogram and equalization]](/img/e7/b8dc55a9febf2b2949fce3a7ac21f9.jpg)
[opencv learning] [image histogram and equalization]

哈希表 AcWing 841. 字符串哈希

VIM super practical guide collection of this one is enough

传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
随机推荐
8 examples of using date commands
Wechat official account payment prompt MCH_ ID parameter format error
Js2day (also i++ and ++i, if statements, ternary operators, switch, while statements, for loop statements)
Interval DP acwing 282 Stone merging
阿里发布的Redis开发文档,涵盖了所有的redis操作
Linear DP acwing 898 Number triangle
Package management tools
模块化 CommonJS ES Module
JS iterator generator asynchronous code processing promise+ generator - > await/async
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
The redis development document released by Alibaba covers all redis operations
[opencv learning] [moving object detection]
Execute any method of any class through reflection
线性DP AcWing 899. 编辑距离
Js5day (event monitoring, function assignment to variables, callback function, environment object this, select all, invert selection cases, tab column cases)
async/await 异步函数
2.6 using recursion and stack - [tower of Hanoi problem]
Use MySQL events to regularly perform post seven world line tasks
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
Dijkstra AcWing 850. Dijkstra求最短路 II