Baldy
Baldy

Reputation: 3659

Autofac Conventions for Generic Types

Im new to Autofac and finding myself repeating a lot of this....

builder.RegisterType<ConcreteService<EntityA>>().As<IService<EntityA>>();
builder.RegisterType<ConcreteService<EntityB>>().As<IService<EntityB>>();

EntityA, EntityB, EntityC and so on.. all inherit from EntityBase, so i want to instruct Autofac to always use ConcreteService<x> when it needs to create an implementation of IService<x> as long as x inherits from EntityBase

I am aware that the AssemblyScanner in Autofac may be able to help with this, although i am struggling to find documentation that goes far enough into it.

Any pointers appreciated.

Upvotes: 0

Views: 321

Answers (1)

vhallac
vhallac

Reputation: 13907

I think the answer to this question (stackoverflow) may also answer your question.

Upvotes: 1

Related Questions