Scrutor icon indicating copy to clipboard operation
Scrutor copied to clipboard

Can we get an AddInterfaces() comparable to AddClasses()

Open dotnetchris opened this issue 7 years ago • 2 comments

I wanted to use Scrutor to register all of my https://github.com/reactiveui/refit interfaces to RestService.For<T> however there doesn't seem to be any obvious ways to do this since I don't have any classes at all for these.

dotnetchris avatar Dec 05 '18 19:12 dotnetchris

I'm not sure this is the right library for this. The library is designed in a specific way, which wouldn't match what you're trying to do here:

  1. Select assemblies to scan
  2. Find ImplementationType using the AddClasses method.
  3. Select the ServiceType using one of the As* methods.
  4. Choose a lifetime using the With*Lifetime.

I think what you want to do would be something like

  1. Select assemblies to scan
  2. Find ServiceType using an AddInterfaces method.
  3. Specify an ImplementationFactory using a UseFactory method. The factory would be something like interfaceType => provider => RestService.For(interfaceType).
  4. Choose a lifetime using the With*Lifetime.

As you can see, step 2. and 3. (service type and implementation type/factory selection) has been swapped, while the names of the methods follows the same conventions, which I think would be very confusing.

khellang avatar Dec 05 '18 20:12 khellang

I'd really like this project to be able to end the need to ever write typeof(Foo).Assembly.GetTypes().Where().ForEach()...

I've already used it in many 'unsupported' manners by simply using return false to prevent any built in registration behavior from kicking in.

The only scenario I haven't been able to cover is for interface only scanning.

dotnetchris avatar Dec 10 '18 17:12 dotnetchris