dansiegel/Prism.Container.Extensions

Register assembly in container

SalimiHabib opened this issue · 4 comments

how can register all types in assembly at once ?
my setup is

`    <PackageReference Include="Prism.DryIoc.Extensions" Version="7.2.0.1054" />

    <PackageReference Include="Prism.Forms.Extended" Version="7.2.0.1054" /> 

    <PackageReference Include="Shiny.Prism" Version="7.2.0.1054" />
`

Also some types are internal with public constructor in that assembly that need to be registered

thank you

dadhi commented

Just for the reference, in DryIoc you will register the assemblies via RegisterMany with the optional argument nonPublicServiceTypes: true.

@dansiegel Is it translated to the Prism api? I think that maybe not all of the supported IoCs have this option.

base on @dadhi post i try this

` protected override void RegisterTypes(IContainerRegistry containerRegistry)
{

        containerRegistry.RegisterSingleton<IAppInfo, AppInfoImplementation>();
        containerRegistry.RegisterSingleton<IPoolConfigurator, PoolConfigurator>();

        containerRegistry.RegisterSingleton<IEdgeClientService, EdgeClientService>();

        var implTypes = typeof(IEdgeProvisioningService).GetAssembly().GetTypes()  ;
        PrismContainerExtension.Current.Instance.RegisterMany(implTypes, nonPublicServiceTypes: true); `

and i got this error on RegisterMany method
concrete implementation exist but with internal access modifier and public constructor

DryIoc.ContainerException Message=code: RegisteringAbstractImplementationTypeAndNoFactoryMethod; message: Registering abstract implementation type Hyperledger.Aries.Agents.Edge.IEdgeProvisioningService when it is should be concrete. Also there is not FactoryMethod to use instead.

dadhi commented

var implTypes = typeof(IEdgeProvisioningService).GetAssembly().GetTypes()

Filter your implementation types:

var implTypes = typeof(IEdgeProvisioningService).GetAssembly().GetTypes().Where(t => t.IsImplementationType());

Here are all the goodies https://www.fuget.org/packages/DryIoc.dll/4.4.1/lib/netstandard2.0/DryIoc.dll/DryIoc/Registrator, search for IsImplementationType

automatic registration of an assembly isn't something I'm going to do for Prism or the Container Extensions here. However this sort of functionality is something that I'm open to duplicating for the Prism.Magician.

That said the RegisterMany in Prism should pull in any interface that is on a given type if you do not specify any service types.

https://github.com/PrismLibrary/Prism/blob/261790736d7f73491d6baffcd35de6afee27f97b/src/Containers/Prism.DryIoc.Shared/DryIocContainerExtension.cs#L152-L161