c# - IS this the right way to automate the user defined service import in Built in DI in asp.net-core -


i have created extension method adding services defined under particular namespace scoped in di. works well.

public static class servicecollectionextensions {     public static void addscopedimplementations(this iservicecollection services)     {                    foreach (type type in assembly.getentryassembly().gettypes()           .where(t => t.namespace == "serverapi.services")           .where(t => !t.gettypeinfo().isdefined(typeof(compilergeneratedattribute),true))           .where(t => t.gettypeinfo().isclass))         {             services.addscoped(type.gettypeinfo().getinterface("i" + type.name), type);         }     }        } 

my question is: right way in built di in asp.net-core?

like said, works. but, locks "serverapi.services" namespace. have give every single class interface of same name starts "i", in cases should not necessary. you're giving every dependency scoped lifetime, registrations should transient unless there's reason them not be.

in other words, implementation restrict flexibility framework. if you're okay that, it's fine.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -