对于.NET架构的LINQ to SQL最佳设计实践(必要DAL?我们才能真正使用波苏斯?设计模式采用?)架构、必要、才能、模式

2023-09-03 08:47:41 作者:一点一点侵蚀

我是避免写的什么,似乎是在.NET弓/ n层体系结构的另一个线程,但多多包涵。

I was avoiding writing what may seem like another thread on .net arch/n-tier architecture, but bear with me.

我,希望能像其他人一样仍然不是100%满意或清除的最佳方法采取在今天的趋势和新出现的技术,当谈到选择一个架构用于企业应用程序。

I, hopefully like others still am not 100% satisfied or clear on the best approach to take given today's trends and new emerging technologies when it comes to selecting an architecture to use for enterprise applications.

我想我正在寻找的方向和建筑实施的您的建设将利用今天的.NET技术和什么方向最方面你会采取一个企业应用程序时,选择了社区群众的意见。我更好地使这对我和我的问题,在这种恐惧过于含糊,否则的;我想提高我的架构,以改善和真的想听听你们的想法给予了技术,我要写列表中。

I suppose I am seeking mass community opinion on the direction and architectural implementation you would chose when building an enterprise application utilising most facets of today's .NET technology and what direction you would take. I better make this about me and my question, in fear of this being too vague otherwise; I would like to improve my architecture to improve and would really like to hear what you guys think given the list of technologies I am about to write.

任何及所有的最佳实践和架构模式,你会建议,欢迎,如果你创建了一个解决方案之前,一个类似类型的设置,任何缺陷或警告,你可能已经打或克服。

Any and all best practices and architectural patterns you would suggest are welcome and if you have created a solution before for a similar type setup, any pitfalls or caveats you may have hit or overcome.

下面是技术清单采用我的最新项目,是的pretty的每样东西,除了WPF:)

Here is a list of technologies adopted in my latest project, yep pretty much everything except WPF :)

在智能客户端(的WinForms) 在WCF 的使用的智能客户端的 Smart Client (WinForms) WCF Used by Smart Client 的管理工具的 的客户端工具的 Admin tool Client tool 的使用的WCF 的 的使用ASP.NET MVC 的 Used by WCF Used ASP.NET MVC

实用程序和附加组件来考虑:

Utilities and additional components to consider:

依赖注入 - StructureMap 在异常管理 - 自定义 在单元测试 - MbUnit的

我现在有n层拱此运行。采用的基于服务的的设计模式,采用请求/响应(不知道它的正式名称)和存储库模式,我的大部分结构从的罗布科纳的店面。

I currently have this running in an n-Tier arch. adopting a Service-based design pattern utilising Request/Response (Not sure of it's formal name) and the Repository pattern, most of my structure was adopted from Rob Conery's Storefront.

我想我或多或少高兴与我的大部分层(它实际上只是这我就有点不安的DAL)。

I suppose I am more or less happy with most of my tiers (It's really just the DAL which I am a bit uneasy on).

在我结束之前,这些都是我所面对我现在的体系结构中的真正问题:

Before I finish, these are the real questions I have faced with my current architecture:

我有我是否应该给使用LINQ到SQL自定义数据访问层一个大大的问号。我应该执行的LINQ to SQL直接在我的服务/业务层或在DAL在存储库的方法?如果你在每个存储库方法调用创建您的数据库环境的一个新实例(使用使用())?或者一个在类的构造函数/通过人工授精?

I have a big question mark on if I should have a custom data access layer given the use of LINQ to SQL. Should I perform LINQ to SQL directly in my service/business layer or in a DAL in a repository method? Should you create a new instance of your DB context in each repository method call (using using())? or one in the class constructor/through DI?

你相信,我们可以使用LINQ to SQL时真正使用POCO(普通旧CLR对象)?我很想看到一些例子,我遇到的问题,这将是非常方便的与WCF的工作,因为我不能明显地跨线携带L2S对象。

Do you believe we can truly use POCO (plain old CLR objects) when using LINQ to SQL? I would love to see some examples as I encountered problems and it would have been particularly handy with the WCF work as I can't obviously be carrying L2S objects across the wire.

自行创建ASP.NET MVC项目非常清楚地显示了设计模式,你应该采取,通过保持视图逻辑视图,控制器调用服务/业务方法,当然在模型中的数据访问,但你会下降的模式方面的大型项目中,特别是在数据访问是共享的,有什么办法,你才能让你的数据?

Creating an ASP.NET MVC project by itself quite clearly displays the design pattern you should adopt, by keeping view logic in the view, controller calling service/business methods and of course your data access in the model, but would you drop the 'model' facet for larger projects, particularly where the data access is shared, what approach would you take to get your data?

谢谢你听我的意见,并希望能看到在架构样品code-基地,它是如何分裂。正如说我所看到的店面,我还没有真正经过Oxite但只是认为这将有利于自己和大家。

Thanks for hearing me out and would love to see sample code-bases on architectures and how it is split. As said I have seen Storefront, I am yet to really go through Oxite but just thought it would benefit myself and everyone.

在DAL小点的的添加了更多的问题。 / 15:42 GMT + 10 的

Added additional question in DAL bullet point. / 15:42 GMT+10

推荐答案

要回答你的问题:

我应该执行LINQ直接在我的服务/业务层或在存储库方法的DAL SQL?的LINQ to SQL专才有意义,如果你的数据库映射1,于─ 1与您的业务对象。在大多数企业的情况是不是这样和实体是比较合适的。

Should I perform LINQ to SQL directly in my service/business layer or in a DAL in a repository method? LINQ to SQL specifically only makes sense if your database maps 1-to-1 with your business objects. In most enterprise situations that's not the case and Entities is more appropriate.

这是所说的,一般LINQ是直接在业务层使用非常合适的,因为LINQ提供程序(这是否是LINQ to SQL的或别的什么)的是的你的DAL。 LINQ的好处是,它可以让你更加灵活和EX pressive在业务层比 DAL.GetBusinessEntityById(ID),但贴近-the金属code,这使得双方LINQ和传统的DAL code的工作被封装离你有同样的积极效果。

That having been said, LINQ in general is highly appropriate to use directly in your business layer, because the LINQ provider (whether that is LINQ to SQL or something else) is your DAL. The benefit of LINQ is that it allows you to be much more flexible and expressive in your business layer than DAL.GetBusinessEntityById(id), but the close-to-the-metal code which makes both LINQ and the traditional DAL code work are encapsulated away from you, having the same positive effect.

你相信,我们可以真正使用POCO(普通旧CLR对象)使用LINQ时,SQL?如果没有就有关LINQ到SQL的POCO的问题更具体的信息,这是很难说

Do you believe we can truly use POCO (plain old CLR objects) when using LINQ to SQL? Without more specific info on your POCO problems regarding LINQ to SQL, it's difficult to say.

你会下降的模式方面的大型项目一般MVC模式是更为广阔的不是肤浅的看一下ASP.NET MVC可能暗示。根据定义,无论您选择使用连接到您的数据备份您的应用程序将成为您的模型。如果是利用WCF或MQ连接到企业数据云,就这样吧。

would you drop the 'model' facet for larger projects The MVC pattern in general is far more broad than a superficial look at ASP.NET MVC might imply. By definition, whatever you choose to use to connect to your data backing in your application becomes your model. If that is utilizing WCF or MQ to connect to an enterprise data cloud, so be it.