0

I am not very experienced in design patterns.

I am creating an webapi application using asp.net core 2.0. I want to implement a design pattern so that i can configure whether to use database repository to save to sql database or file repository for saving to file or i will use messaging service to send as a message to a queue.

Can anyone suggest me what is the best pattern to achieve this?

3
  • 1
    "I want to implement a design pattern" Keep in mind, that design patterns are not blueprints for implementations - they are meant as a way of communicating a basic idea or concept to other developers. Commented Mar 27, 2018 at 9:14
  • You can use ServiceLocator Pattren. And base of app configuration return correct Implementation of data access Interface. Commented Mar 27, 2018 at 9:26
  • Do you want to encapsulate object Creation or Behaviour ? meaning your concern is how to create these 3 types of objects at the runtime or objects will be created already you want to dynamically save to different Target for every request\response ? Commented Dec 7, 2022 at 8:43

1 Answer 1

1

I don't think you need a pattern here. You need to adhere to the SOLID design principles and, in particular, the Dependency Inversion Principle.

Create an interface for your repository and depend on that where you want to use it. Inject the appropriate concrete implementation (database or file) as necessary. Take a look at my answer here for some, highly contrived, ideas.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. It really helps.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.