现在我有一个DataAccess层(DAL),包含在单独的命名空间中,对于每个BLL对象,我有一个DataClass或Repository它执行getById并保存命令。所以在某种程度上,BLL保存和getById方法是围绕DataClass方法的薄层。
public static NewsItem GetByID id) { return DataFactory.GetNewsItemRepository()。GetNewsItemById(id); }为了让DataClasses返回BLL对象,他们需要知道BLL 。所以现在我们有:
GUI ---> BLL< ---- DAL
DataFactory只返回实现接口的对象,所以我可以隐藏实现细节,如OracleNewsItemRepository。
但是现在,自从我启动Object以来,面向编程。在我目前的解决方案中,BLL和DAL都需要彼此了解。这是一个循环依赖,最佳做法是避免循环依赖。另外我只想公开接口(和我的DataFactory)而不是我的类。这可以通过将DAL层放置在单独的组件中来完成。这是有道理的。但是,Visual Studio不允许两个程序集引用彼此。另一个问题: C#内部访问修饰符
不知怎的,我觉得我的整个数据访问模式错了。感觉像我将ActiveRecord模式与DataMappers等其他东西进行卷积。我花了很多时间在Martin Fowler的网站上,但是这些模式被描述得非常通用,并且被非常抽象的UML图解释。
他们没有解决我的问题。也许我有点肛门,没有像完美的数据访问模式这样的东西。我现在做的并不是非常错误。但是我现在做什么,似乎... ...
任何想法?
解决方案我认为你的数据访问模式很好。你没有做的是将BLL与OracleDAL结合在一起。您连接到DAL接口。一定程度的耦合是绝对需要的,或者你永远都不会做任何事情。
我假设你的DataFactory和INewsItemRepository类存在于你的DAL层之外。以下是我的解决方案如何组织的一个例子。我不使用ActiveRecord,所以这可能不太适合你。
核心(项目)域业务实体数据存储库接口 **您的DataFactory ** OracleData(Project)数据 Oracle Repository实现 SqlData(Project)数据 Sql存储库实现 UI(项目)希望这有帮助。
I’m having a little Architecture problem. In my project I have a Business Logic Layer (BLL) that contains all my business rules, models and OO API for the interface. Each object has static methods like getById that return an instance of said object. Each object also has methods like save and, delete. This is very straightforward OO code.
Now I have a DataAccess layer (DAL), contained in a separate namespace, for each BLL object I have a DataClass or "Repository" which executes the getById and save commands. So in a way, the BLL save and getById methods are a thin layer around the DataClass methods.
public static NewsItem GetByID(int id) { return DataFactory.GetNewsItemRepository().GetNewsItemById(id); }In order for the DataClasses to return BLL objects, they need to know the BLL. so now we have:
GUI ---> BLL <---->DAL
The DataFactory only returns objects that implement an Interface, so I can hide implementation details like "OracleNewsItemRepository".
But now for the thing that has been bugging me ever since I started Object Oriented programming. In my current solution, both BLL and the DAL need to know each other. This is a Circular Dependency, and it is best practice to avoid circular dependencies. Also I only want to expose the interfaces (and my DataFactory) and not my classes. This can be done by placing the DAL layer in a separate Assembly. Which would make sense. However, Visual Studio does not allow two Assemblies to refer eachother. Another question about this: C# internal access modifiers
Somehow I think I got my whole data access pattern wrong. It feels like I am convoluting the ActiveRecord pattern with other stuff like DataMappers. I have spent a lot of time on Martin Fowler’s site, but those patterns are described very generic and are illustrated by a very abstract UML diagram.
They don’t solve my problem. Maybe I’m a bit anal, and there is no such thing as a "perfect data access pattern". And what I do now doesn’t seem terribly wrong. But how I do things now, seems off…
Any ideas?
解决方案I think your data access pattern is fine. What you are not doing is coupling your BLL to the OracleDAL. You are coupling to the DAL interfaces. A certain bit of coupling is absolutely required or you could never get anything done.
I assume that your DataFactory and the INewsItemRepository classes exist outside your DAL Layer. The following is an example of how my solutions are organized. I don't use ActiveRecord, so this may not suit you perfectly.
Core (Project) Domain Business Entities Data Repository Interfaces **Your DataFactory** OracleData (Project) Data Oracle Repository Implementations SqlData (Project) Data Sql Repository Implementations UI (Project)Hope this helps.
更多推荐
业务逻辑层和数据访问层:循环依赖
发布评论