分层数据上下文和抽象
我正在为我们的一个内部项目创建一个核心库。该核心库应该包含一些抽象类和通用类,然后将通过专门的项目对其进行扩展。例如,有一个 AbstractPerson 类,具有 Person 类的标准属性和方法,而另一个项目将实现一个 Person 类,该类将从 AbstractPerson 类继承以添加项目特定的功能。 现在我们需要为这个常见和专门的项目实施DAL。由于大多数操作都是通用的,所以我想将它们作为存储库类包含到核心库中。但是,Repository 类需要访问 LINQ dataContext。这是从专门的数据库生成的。因此,核心库中没有可用的 dataContext 可以工作。那么我如何才能为可以驻留在公共库中的通用方法创建公共存储库类。
I am creating a core library for one of our internal project. This core library supposed to contain some abstract classes and generic classes which will then be extended by specialized projects. For example, There is an AbstractPerson class with standard properties and methods for a Person class while another project will implement a Person class which will inherit from the AbstractPerson class to add project specific functionality.
Now we need to impelment DAL for this common and specialized projects.As most of operations are generic so i want to include them into core library as Repository classes. However, Repository classes need to access LINQ dataContext. Which is generated from the specialized databases. Hence there is no dataContext available in Core library to work. So how could i can create a common repository classes for generic methods which can reside in the common library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以依靠 DataContext 来实现特定接口(即使只是说“这些集合存在!”)?
如果是这样,通过将存储库的上下文设置为构造函数中传递的值,或者允许在每个函数调用中传递上下文,您可以注入要使用的 DataContext,只要它实现所需的接口即可。
如果将上下文作为参数传递给存储库构造函数/工厂方法/其他内容,那就更漂亮了。
Can you rely on your DataContexts to implement a particular interface (even if only to say "These collections are present!")?
If so, by setting the context of the repository to a value passed in on the constructor, or allowing a context to be passed in each function call, you can inject the DataContext you want to use, as long as it implements the required interface.
It's a little prettier if you pass the context as a parameter to the repository constructor/factory method/whatever.