CSLA 是否应该与依赖注入框架一起使用?
我的开发团队正在评估可用于 .NET 的各种框架来简化我们的编程,其中之一是 CSLA。我不得不承认,我对 CSLA 是否会从与依赖注入框架(例如 Spring.net 或 Windsor)结合使用中受益感到有点困惑。如果我们将这两个 DI 框架之一与实体框架相结合来处理 ORM 职责,这是否会完全否定使用 CSLA 的需要或好处?
我对所有这些框架有不同程度的理解,并且我试图全面了解什么最有利于我们的企业架构和对象设计。
谢谢你!
My development team is evaluating the various frameworks available for .NET to simplify our programming, one of which is CSLA. I have to admit to being a bit confused as to whether or not CSLA would benefit from being used in conjunction with a dependency injection framework, such as Spring.net or Windsor. If we combined one of those two DI frameworks with, say, the Entity Framework to handle ORM duties, does that negate the need or benefit of using CSLA altogether?
I have various levels of understanding of all these frameworks, and I'm trying to get a big picture of what will best benefit our enterprise architecture and object design.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CSLA 是一个用于创建业务实体的框架,因此与 IoC 容器或 ORM 有着不同的关注点。在企业应用程序中,您应该考虑这三者的好处。
特别是,如果您希望将数据绑定内置到模型中、脏检查、N 级撤消、验证和业务规则,以及允许轻松配置 n 层部署的数据门户实现,则应该考虑 CSLA。
CSLA is a framework for creating business entities, so has separate concerns than an IoC container or ORM. In a enterprise application you should consider the benefits of all three.
In particular, you should consider CSLA if you want data binding built in to your models, dirty checking, N-level undo, validation and business rules, as well as the data portal implementation which allows easy configuration for n-tier deployments.
简短回答:是的。
长答案:它需要一些繁重的工作和一些实验来设置,但它可以在不从根本上破坏 CSLA 的情况下完成。我使用 StructureMap 和存储库模式组合了一个工作原型,并使用了 Setter 注入的 BuildUp 方法在 CSLA 中注入。我使用了一种类似于 此处 确保在序列化对象时重新注入我的业务对象。
我还使用 StructureMap 的注册表基类将我的配置分为演示文稿、CSLA 客户端、CSLA 服务器和 CSLA 全局设置。这样,我可以使用 Visual Studio 的链接文件功能将 CSLA 服务器和 CSLA 全局配置文件包含在服务器端数据门户中,并且两个位置的配置始终相同。这是为了确保我仍然可以将 CSLA 中的数据门户配置设置从 2 层更改为 3 层,而不会破坏任何内容。
无论如何,我仍在权衡使用 DI 的潜在好处和缺点,但到目前为止,我倾向于使用它,因为测试会容易得多,尽管我对尝试使用 DI 的任何高级功能持怀疑态度,例如作为拦截。我建议阅读 Mark Seemann 的.NET 中的依赖注入一书来了解使用 DI 的方式有正确和错误之分,因为互联网上有很多错误信息。
Short answer: Yes.
Long answer: It requires a bit of grunt work and some experimentation to setup, but it can be done without fundamentally breaking CSLA. I put together a working prototype using StructureMap and the repository pattern and used the BuildUp method of Setter Injection to inject within CSLA. I used a method similar to the one found here to ensure that my business objects are re-injected when the objects are serialized.
I also use the registry base class of StructureMap to separate my configuration into presentation, CSLA client, CSLA server, and CSLA global settings. This way I can use the linked file feature of Visual Studio to include the CSLA server and CSLA global configuration files within the server-side Data Portal and the configuration will always be the same in both places. This was to ensure I can still change the Data Portal configuration settings in CSLA from 2 tier to 3 tier without breaking anything.
Anyway, I am still weighing the potential benefits with the drawbacks to using DI, but so far I am leaning in the direction of using it because testing will be much easier although I am skeptical of trying to use any of the advanced features of DI such as interception. I recommend reading the book Dependency Injection in .NET by Mark Seemann to understand the right and wrong way to use DI because there is a lot of misinformation on the Internet.