Register all classes implementing 1 certain interface

41 views
Skip to first unread message

arieny...@gmail.com

unread,
May 20, 2015, 11:40:55 AM5/20/15
to aut...@googlegroups.com
Hey all,

MY current Autofac config has the following 2 lines:

builder.RegisterGeneric(typeof(LookupFunctions<>)).As(typeof(ILookupFunctions<>)).InstancePerRequest();
builder.RegisterType(typeof(CountryLookupFunctions)).As(typeof(ILookupFunctions<Country>)).InstancePerRequest();

The first is a generic solution, while the second is a specific one for all ILookupFunction implementations where T is of type Country.

It could be that in the future more specific ones are added. I've heard it is possible to scan an assembly and then register them all at once, but I'm unable to get this working with Autofac.

Anyone got an idea?

Thanks in advance and kind regards,

Yannick

Travis Illig

unread,
May 28, 2015, 12:41:52 PM5/28/15
to aut...@googlegroups.com, arieny...@gmail.com, arieny...@gmail.com
There is some documentation on assembly scanning for registrations with examples. You could use a Where clause to filter out types that implement ILookupFunctions<T> and register them AsImplementedInterfaces or whatever.

(Note that this sort of usage question is a great thing to ask over on StackOverflow and tag it with "autofac" - we have a great community that participates over there. If you do post over there, please post a link to the question here so we can continue the discussion on StackOverflow.)
Reply all
Reply to author
Forward
0 new messages