Reputation: 1538
We are building an api for a client. We are using dependency injection for setting the business logic classes and the repository classes when calling the api method.
We have as scenario that a new client will be using our api service but they have slightly different business rule. The question I have is, what is the best way to handle the custom business logic.
I am leaning towards injecting the Custom business logic via DI based on the client (this could done by examining the api key, which is specific to client).
Thoughts much appreciated.
Upvotes: 1
Views: 145
Reputation: 1456
Yeah, you could use an interface as a contract for your business logic.
For example IOrder where client specific classes can inherit from:
In the container you register your interface IOrder and the specific concrete class (e.g. Client1OrderProcess) you want to use after based on your API key. From there on it is just a matter of executing the business logic as defined in the instantiated concrete class.
Upvotes: 1