如果有人向我解释编译.dll时.NET引用的工作原理,我将不胜感激。
我有两个.dll-s,我的主要application.dll引用了我的services.dll。 services.dll的目的是提供一个与第三方服务进行通信的分离层,以使对集成的更改不会直接影响应用程序。
为了实现这种分离,我继承了服务主对象,该对象在主应用程序中公开并使用了新对象:
<style type="text/css" >
#T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col0 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col1 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col2 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col3 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col4 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col0 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col1 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col2 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col3 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col4 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col0 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col1 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col2 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col3 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col4 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col0 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col1 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col2 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col3 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col4 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col0 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col1 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col2 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col3 {
background-color: yellow;
} #T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col4 {
background-color: yellow;
}</style>
<table id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3" >
<thead> <tr>
<th class="blank level0" ></th>
<th class="col_heading level0 col0" >A</th>
<th class="col_heading level0 col1" >B</th>
<th class="col_heading level0 col2" >C</th>
<th class="col_heading level0 col3" >D</th>
<th class="col_heading level0 col4" >E</th>
</tr></thead>
<tbody> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row0" class="row_heading level0 row0" >0</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col0" class="data row0 col0" >1</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col1" class="data row0 col1" >1.32921</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col2" class="data row0 col2" >nan</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col3" class="data row0 col3" >-0.31628</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row0_col4" class="data row0 col4" >-0.99081</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row1" class="row_heading level0 row1" >1</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col0" class="data row1 col0" >2</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col1" class="data row1 col1" >-1.07082</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col2" class="data row1 col2" >-1.43871</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col3" class="data row1 col3" >0.564417</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row1_col4" class="data row1 col4" >0.295722</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row2" class="row_heading level0 row2" >2</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col0" class="data row2 col0" >3</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col1" class="data row2 col1" >-1.6264</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col2" class="data row2 col2" >0.219565</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col3" class="data row2 col3" >0.678805</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row2_col4" class="data row2 col4" >1.88927</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row3" class="row_heading level0 row3" >3</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col0" class="data row3 col0" >4</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col1" class="data row3 col1" >0.961538</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col2" class="data row3 col2" >0.104011</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col3" class="data row3 col3" >-0.481165</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row3_col4" class="data row3 col4" >0.850229</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row4" class="row_heading level0 row4" >4</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col0" class="data row4 col0" >5</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col1" class="data row4 col1" >1.45342</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col2" class="data row4 col2" >1.05774</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col3" class="data row4 col3" >0.165562</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row4_col4" class="data row4 col4" >0.515018</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row5" class="row_heading level0 row5" >5</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col0" class="data row5 col0" >6</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col1" class="data row5 col1" >-1.33694</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col2" class="data row5 col2" >0.562861</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col3" class="data row5 col3" >1.39285</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row5_col4" class="data row5 col4" >-0.063328</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row6" class="row_heading level0 row6" >6</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col0" class="data row6 col0" >7</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col1" class="data row6 col1" >0.121668</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col2" class="data row6 col2" >1.2076</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col3" class="data row6 col3" >-0.00204021</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row6_col4" class="data row6 col4" >1.6278</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row7" class="row_heading level0 row7" >7</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col0" class="data row7 col0" >8</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col1" class="data row7 col1" >0.354493</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col2" class="data row7 col2" >1.03753</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col3" class="data row7 col3" >-0.385684</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row7_col4" class="data row7 col4" >0.519818</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row8" class="row_heading level0 row8" >8</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col0" class="data row8 col0" >9</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col1" class="data row8 col1" >1.68658</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col2" class="data row8 col2" >-1.32596</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col3" class="data row8 col3" >1.42898</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row8_col4" class="data row8 col4" >-2.08935</td>
</tr> <tr>
<th id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3level0_row9" class="row_heading level0 row9" >9</th>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col0" class="data row9 col0" >10</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col1" class="data row9 col1" >-0.12982</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col2" class="data row9 col2" >0.631523</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col3" class="data row9 col3" >-0.586538</td>
<td id="T_0189b640_cb1a_11e8_b68b_c8d3ffd26fc3row9_col4" class="data row9 col4" >0.29072</td>
</tr></tbody>
</table>
但是,我发现当ServiceClient_v1更新为ServiceClient_v2时,我尝试仅更新services.dll,然后我的application.dll爆炸了:
无法从程序集services.dll中加载类型“ ServiceClient_v1”
因此,它仍然挂在我要隐藏的其他对象的直接引用上。我认为这是设计使然,只是与我不了解的编译有关。
有没有办法实现我想要的?为什么我的方法不起作用?
答案 0 :(得分:1)
由于您是从CustomClient
中的ServiceClient_v1
派生出application.dll
的,因此它仅适用于包含{{1 }}。正如LasseVågsætherKarlsen指出的那样,services.dll
类成为ServiceClient_v1
的公共声明的一部分。
我相信您可以在自己的应用程序中应用Dependency Injection和Liskov substitution principle。
为了实现真正可互换的ServiceClient_v1
的目标,您需要重构体系结构,从CustomClient
中删除services.dll
的依赖性,这应该是相反的。
答案 1 :(得分:0)
为您的ServiceClient
类型定义一个Interface。 CustomClient
和ServiceClient_v1
都必须实现此接口。
稍后您更新代码以使用ServiceClient_v2
时,它还应该实现接口,该接口将保持不变。现在,一切都可以继续进行,而无需重新编译application.dll
项目。
或者,从v1迁移到v2时,不要在services.dll中重命名ServiceClient
类型。 这是git或SVN之类的版本控制系统或用于的版本。