开发者

ASP.NET How to implement ObjectDataSource and IRepository

开发者 https://www.devze.com 2022-12-19 22:22 出处:网络
I\'d like to use ObjectDataSource with an instance that implements IRepository. I\'d also like to be able to flexibly change the IRepository implementation through dependency injection, and switch bet

I'd like to use ObjectDataSource with an instance that implements IRepository. I'd also like to be able to flexibly change the IRepository implementation through dependency injection, and switch between one that uses ORM and a fake.

I currently don't see a way to do this because the ODS points to a class instead of an instance. Is there a way around this?

I'm looking along the lines of having a data source class that calls a factory that creates the appropriate IRepository implemenation depending on conf开发者_高级运维iguration settings. However, I will have to create the implementation everytime this data source class is called, which may be expensive.


I'm not 100% sure what you're trying to do, but I think you'll have to handle the ODS's "ing" events: ObjectCreating, ObjectInserting, etc. By handling these events you can use any data access strategy you want. Of course if you follow this path then the ODS adds little value to your application.

Manuel Abadia has written an excellent series of articles that discuss the limitations of the ODS control.

0

精彩评论

暂无评论...
验证码 换一张
取 消