Rookian
Rookian

Reputation: 20549

StructureMap: How to use more than one concrete Class per Interface

How can I figure StructureMap to use more than one concrete Class per Interface. i.e. an IRepositoryCustomer is implemented by: RepositoryCustomerA and RepositoryCustomerB

How do I register and resolve this to/from the StructureMap IoC container?

Upvotes: 1

Views: 1389

Answers (1)

ladenedge
ladenedge

Reputation: 13419

You first need to answer the question, "when do I want RepositoryCustomerA instead of RepositoryCustomerB?"

If either of those classes could be instantiated in production based on some runtime state, then you probably want to look into conditional object construction.

If RepositoryCustomerA should be instantiated at development time (for unit testing, say) while RepositoryCustomerB is the production analog, then you need two distinct Registrys: one that exists only in your test code, and one that is accessible in production. For more on this route, read about creating registries as a means of configuring StructureMap.

Upvotes: 2

Related Questions