当前位置:网站首页>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边栏推荐
- Obtain file copyright information
- bellman-ford AcWing 853. Shortest path with side limit
- Linear DP acwing 897 Longest common subsequence
- 线性DP AcWing 897. 最长公共子序列
- JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
- Ntmfs4c05nt1g N-ch 30V 11.9a MOS tube, pdf
- Variable, "+" sign, data type
- 2.6 using recursion and stack - [tower of Hanoi problem]
- js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
- 国产免费数据仓库ETL调度自动化运维专家—TASKCTL
猜你喜欢
Modular commonjs es module
Bom Dom
spfa AcWing 851. SPFA finding the shortest path
[opencv learning] [image filtering]
Five best software architecture patterns that architects must understand
js2day(又是i++和++i,if语句,三元运算符,switch、while语句,for循环语句)
Interval DP acwing 282 Stone merging
线性DP AcWing 896. 最长上升子序列 II
Variable, "+" sign, data type
计数类DP AcWing 900. 整数划分
随机推荐
The redis development document released by Alibaba covers all redis operations
js4day(DOM开始:获取DOM元素内容,修改元素样式,修改表单元素属性,setInterval定时器,轮播图案例)
Js1day (syntaxe d'entrée / sortie, type de données, conversion de type de données, Var et let différenciés)
线性DP AcWing 896. 最长上升子序列 II
Variable, "+" sign, data type
VIM super practical guide collection of this one is enough
Oracle from entry to mastery (4th Edition)
Interview questions for software testing - a collection of interview questions for large factories in 2022
JS7day(事件对象,事件流,事件捕获和冒泡,阻止事件流动,事件委托,学生信息表案例)
Linear DP acwing 896 Longest ascending subsequence II
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
About asp Net MVC project in local vs running response time is too long to access, the solution!
About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution
Bom Dom
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
js 迭代器 生成器 异步代码处理 promise+生成器 -> await/async
[opencv learning] [image pyramid]
1380. Lucky numbers in the matrix [two-dimensional array, matrix]
. Net, C # basic knowledge