mardi 13 août 2019

Different Data provider layer, design pattern

I need architectural design solution for services that might be use more than one data provider for crud operation. What will be the best architect design for it, I am using no sql and relational Db

i use the service/repository design pattern in such way that i need to perform crud operation in both providers and it doesn't feel the best architect approach for combine the two providers under the same repository. For example when i invoke from my OrderService --> UpdateOrder. I need to update in 2 Db's and its making the code messy and not clear

Pseudo code

public class OrderRepo : IOrderRepo
    {
        private readonly Provider1 p1;
        private readonly Provider2 p2;

        public OrderRepo(Provider1 p1 , Provider2 p2)
        {
            this.p1 = p1;
            this.p2 = p2;
        }

        public void UpdateOrder(string orderId)
        {
            // performe update in p1 and p2 ?how should i seprate this two 
            // providers

        }

        public Order GetOrder(string orderId)
        {
            // when use repository usually there is only one provider
            // now when i name function as "Getorder". which provider do i use 
            //  p1 or p2, its not clear on what i want to use
            // should i   name it GetOrder1 and do the same For  GetOrder2
        }




    }

I believe that the desire result is to change architecture or maybe create another layer but i am not sure how and what is the best way for achieving it.

please help me

Aucun commentaire:

Enregistrer un commentaire