unitycontainer / registration-by-convention

Unity.RegistrationByConvention package (Requires Core Implementation. Any contributors?)
Apache License 2.0
4 stars 12 forks source link

ApplicationModel.Package.Current.InstalledLocation - not supported in Core .NET #2

Open ENikS opened 6 years ago

ENikS commented 6 years ago

Need to find a way to scan installation folder in NET Core app here.

ENikS commented 6 years ago

I deployed Unity.RegistrationByConvention package but it does not provide support for UWP or Core apps.

DaniilSokolyuk commented 6 years ago

Who need registration by convention on core can use good combo with https://github.com/khellang/Scrutor and https://github.com/unitycontainer/microsoft-dependency-injection

ENikS commented 6 years ago

Присылай PR, этот проект уже давно висит, не было времени разобраться

DaniilSokolyuk commented 6 years ago

Да нет PR, это совет для тех кто хочет красивый fluent api и поддержку кора, можно скомбинировать Scrutor и microsoft di

ENikS commented 6 years ago

PR - pull request, у тебя GitHub c русским интерфейсом?

DaniilSokolyuk commented 6 years ago

? можно просто делать с помощью Scrutor что то подобное, вместо использования этой библиотеки

var collection = new ServiceCollection();

collection.Scan(scan => scan
    .FromAssemblyOf<ITransientService>()
        .AddClasses(classes => classes.AssignableTo<ITransientService>())
            .AsImplementedInterfaces()
            .WithTransientLifetime()
        .AddClasses(classes => classes.AssignableTo<IScopedService>())
            .As<IScopedService>()
            .WithScopedLifetime());

 var unityContainer = new UnityContainer();

var serviceProvider = unityContainer.ConfigureServices(collection);
ENikS commented 6 years ago

Можно проще

var collection = new ServiceCollection();

collection.Scan(scan => scan
    .FromAssemblyOf<ITransientService>()
        .AddClasses(classes => classes.AssignableTo<ITransientService>())
            .AsImplementedInterfaces()
            .WithTransientLifetime()
        .AddClasses(classes => classes.AssignableTo<IScopedService>())
            .As<IScopedService>()
            .WithScopedLifetime());

var serviceProvider = ServiceProvider.ConfigureServices(collection);
ZacUSNYR commented 6 years ago

I use UWP and Unity 4.0.1... the registration by convention stuff is the reason I implemented Unity in the first place. But the behavior didn't function in Release mode due to having to use the .NET Native compiler and lack of reflection.

At the time I only needed a single Assembly, therefore doing this.GetType().GetTypeInfo().Assembly would give me the assembly to allow me to pass the assembly name to AllClasses.FromAssemblies().

Manually registering all assemblies at run time seems to work. I think for UWP, could we not safely allow for specifying assemblies to register and bring over the extension methods in Containers to RegisterTypes with mappings?

Specifying an assembly is easier than specifying every type you want to register.

ENikS commented 6 years ago

If you'd like to send a PR I will consider the feature.