简体   繁体   中英

How should I design my business layer to handle Sql Server and Mongo DB based on configuration setting

Currently we are using Sql Server and Entity framework in our application. We have our own custom membership provider which is based on Sql Server. We are using EF as ORM.

We are in the process of updating our application to handle MongoDb as well. We are starting with making changes to Membership Provider.

As of now our BL directly creating instances of entity models and doing db operations. Which I think not a good design.

I want my BL should not get changed based on the DB. It should create an instance of repository object and forward the request(CRUD operation). Repository will take care of communicating with DAL. Please correct me if I am wrong.

I am thinking of creating an interface which will be implemented by repositories and repository getting used from BL. Interface will look like this.

interface IDataRepository
{
   MembershipUser CreateUser(string firstName, stringLastName, string email, string phone); 
}

1). Please advise me a better way of doing it.

2). If my application has different repositories, how the BL should decide which repository it should use. Would be using a Factory pattern good idea for this?

Thanks, Naresh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM