khellang / Scrutor

Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection
MIT License
3.63k stars 239 forks source link

Getting types just found during Scan #213

Closed dario-l closed 1 month ago

dario-l commented 1 year ago

Simply question.

Is there any possibility to take those types just gathered by Scrutor? I do not want to iterate again.

khellang commented 1 year ago

Hey @dario-l! 👋🏻

Not types specifically added by Scrutor, but you can enumerate the descriptors in the service collection to see which types were added.

dario-l commented 1 year ago

Hi @khellang Damn, that's a shame. Scrutor scans for all types that I want to register in contaoner but after that I need to run scan/search method again instead of get the result of that scan straight from scrutor. 😞

Something like this could be great addition. 😃

dario-l commented 1 year ago

Hi @khellang again 😃 Just found a solution. This will work?

        var tempServices = new ServiceCollection();

        tempServices.Scan(  );

        foreach (var x in tempServices)
        {
            services.Add(x);
        }
khellang commented 1 year ago

Yes, that will work 👍

dario-l commented 1 year ago

Great. Thanks 👍🏻

xingzuhui commented 11 months ago

Set do,not single。 services.Add(tempServices.Scan( )); instead if you can。Never intend to use loop if we don't need。

Hi @khellang again 😃 Just found a solution. This will work?

        var tempServices = new ServiceCollection();

        tempServices.Scan(  );

        foreach (var x in tempServices)
        {
            services.Add(x);
        }