很自然地引用.Net程序集吗? [英] Is it ok to reference .Net assemblies liberally?

查看:158
本文介绍了很自然地引用.Net程序集吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个WPF应用程序并使用MVVM模式。



我的解决方案有4个项目,3个类库,Data,Model和ViewModel, WPF可执行文件View。



模型引用WindowsBase有什么问题,以便我可以使用ObservableCollection< T>例如,我可以利用我直观地感觉到我需要的,而不用担心框架中的类的原始目的,例如收集数据绑定。

解决方案

没问题,除非你是保守的;)





所以不,没有一个真正的问题使用这些,特别是如果它们是您正在引用的框架DLL。在您担心此事之前,您应该担心以下一千件事情,如WPF性能一般,数据绑定是通过反射,事件开销等。如果它使您的应用程序更易于维护并为您提供所需的功能,请使用任何部分您需要的系统一旦你创建了实例,一切都会很好。



现在...如果你加载了大量的外部DLL,那么也许这可能是一个问题寻呼,但通常甚至没有办法避免这种容易。我们的个人项目每个都有大约35-40个参考,您只能在第一次通过时获取加载操作。



他们说如果可以,你应该做一个大的程序集。通常你不可以,所以建议甚至没有真正适用。


为了帮助减少应用程序的工作集,您应该选择单个较大的程序集而不是多个较小程序集。如果您有多个程序集总是加载在一起,则应该将它们组合起来并创建一个程序集。



与多个较小程序集相关联的开销可归因于以下:

*为较小的程序集加载元数据的成本。
*触发CLR中预编译映像中的各种内存页,以加载程序集(如果使用Ngen.exe进行预编译)。
* JIT编译时间。
*安全检查。


如果您只使用自己的代码,那么只是为了理智和VS .Net有这么多问题,使用较少,较大的项目可能会更好。


I'm building a WPF application and working with the MVVM pattern.

I have 4 projects in my solution, 3 class libraries, Data, Model and ViewModel and the WPF executable View.

Is there anything wrong with the Model referencing WindowsBase so that I can use ObservableCollection<T> for example or can I just make use of what I intuitively feel I need without worrying about the original purposes of the class in the framework e.g. collection databinding.

解决方案

No problem, unless you are a conservative ;)

So no, there isn't a real issue using these, especially if they are framework dll's like the one you are referencing. There are a thousand things you should worry about before you worry about this one, like WPF performance in general, databinding is through reflection, event overhead, etc. If it makes your app more maintainable and gives you the features you need, use whatever part of System you need. Once you create the instance, everything will be fine anyway.

Now... if you are loading up tons of external dll's, then maybe that could be an issue just from paging, but usually there isn't even a way to avoid that easily. Our individual projects have about 35-40 references each... you only get a load operation on the first time through.

"They" say you should do one big assembly if you can. Usually you can't though, so that advice doesn't even really apply.

To help reduce your application's working set, you should prefer single larger assemblies rather than multiple smaller assemblies. If you have several assemblies that are always loaded together, you should combine them and create a single assembly.

The overhead associated with having multiple smaller assemblies can be attributed to the following:
* The cost of loading metadata for smaller assemblies. * Touching various memory pages in pre-compiled images in the CLR in order to load the assembly (if it is precompiled with Ngen.exe). * JIT compile time. * Security checks.

If you are using only you own code, then just for sanity's sake and the fact that VS.Net has so many issues, using fewer, larger projects would probably be better.

这篇关于很自然地引用.Net程序集吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆