当前位置:网站首页>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边栏推荐
- VLAN experiment
- 百款拿来就能用的网页特效,不来看看吗?
- Package management tools
- js2day(又是i++和++i,if语句,三元运算符,switch、while语句,for循环语句)
- Efficiency comparison between ArrayList and LinkedList
- Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
- async/await 异步函数
- js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)
- 线性DP AcWing 895. 最长上升子序列
- 传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
猜你喜欢
![JDBC 预防sql注入问题与解决方法[PreparedStatement]](/img/32/f71f5a31cdf710704267ff100b85d7.png)
JDBC 预防sql注入问题与解决方法[PreparedStatement]

模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计

Linear DP acwing 896 Longest ascending subsequence II
![[opencv] [image gradient]](/img/37/1f366501e2b4e70ecee6365088167c.jpg)
[opencv] [image gradient]

线性DP AcWing 902. 最短编辑距离

JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)

Async/await asynchronous function

Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six

Interval DP acwing 282 Stone merging

Efficiency comparison between ArrayList and LinkedList
随机推荐
线性DP AcWing 896. 最长上升子序列 II
线性DP AcWing 897. 最长公共子序列
Execute any method of any class through reflection
js2day(又是i++和++i,if语句,三元运算符,switch、while语句,for循环语句)
Linear DP acwing 896 Longest ascending subsequence II
[opencv learning] [image filtering]
Traverse entrylist method correctly
上手报告|今天聊聊腾讯目前在用的微服务架构
Floyd AcWing 854. Floyd finds the shortest path
哈希表 AcWing 840. 模拟散列表
Hash table acwing 841 String hash
Dijkstra AcWing 850. Dijkstra finding the shortest circuit II
架构师必须了解的 5 种最佳软件架构模式
Package management tools
移动式布局(流式布局)
Heap acwing 839 Simulated reactor
[ybtoj advanced training guide] similar string [string] [simulation]
Async/await asynchronous function
The UVM Primer——Chapter2: A Conventional Testbench for the TinyALU
Bom Dom