ipjohnson / Grace

Grace is a feature rich dependency injection container library
MIT License
336 stars 33 forks source link

Registrations #136

Closed mcdis closed 6 years ago

mcdis commented 6 years ago

Can I enumerate type registrations in container? I'm porting some old code based on dead unity to the Grace. So, in one part of code I enumerate all registered types which match pattern IRendererResourceProvider<T> in container (_container.Registrations / Unity) and Resolve/Locate them all.

So, can I do the same in the Grace or I have to make some workaround?

Old code example:

foreach (var registration in (from r in _container.Registrations
                                       where r.RegisteredType.GetGenericInterfaceArgs(typeof(IRendererResourceProvider<>)) != null
                                       select r))
         {
            var resourceProvider = container
               .CreateChildContainer()
               .ChildLog($"resources\\{resourceIndex}")
               .Resolve(registration.RegisteredType);
            container.RegisterInstance(registration.RegisteredType, resourceProvider);
            resourceIndex++;
         }
ipjohnson commented 6 years ago

@mcdis you can access the containers registrations like so _container.StrategyCollectionContainer.GetAllStrategies()