dansiegel / Prism.Container.Extensions

The packages here provide additional extensions around the Prism Ioc abstractions. This allows for more advanced scenarios.
http://prismplugins.com
MIT License
126 stars 27 forks source link

Register assembly in container #150

Closed SalimiHabib closed 4 years ago

SalimiHabib commented 4 years ago

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 4 years ago

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.

SalimiHabib commented 4 years ago

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 4 years ago

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

dansiegel commented 4 years ago

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