user2153675
user2153675

Reputation: 103

app.config separation of implementation

I am interested in the following scenario. There exists a class library that contains a generic repository interface named IRepository. The library also contains multiple implementations of the same interface e.g. UserRepository, ItemRepository and so on. Also I do not able to add external libraries like Unity or other DI containers. My question are:

  1. Is there a way to map implementations of the interface via configuration file (e.g. for the purpose of a repository factory)?
  2. Is it posible to make a configuration file that holds a path to classes that implement interfaces?
  3. If such a possibility exists, is it also possible to create a class that consumes that information (e.g. Factory that uses a specific implementation to generate a repository)?

Upvotes: 2

Views: 108

Answers (1)

Dzianis Yafimau
Dzianis Yafimau

Reputation: 2016

The best approach is to use Unity container anyway. It allows to do something like that in config file:

<container>
  <register type="ILogger" mapTo="EventLogLogger" /> 
</container>

Or you can do the same by yourself reading config sections and creating instances using reflection at application start up

Upvotes: 1

Related Questions