New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for vnext/.net 5.0? #42

Closed
falconmick opened this Issue Jan 17, 2016 · 7 comments

Comments

5 participants
@falconmick

Just wondering if Unity has support for vnext yet? I've only seen blog posts showing people usign ifdef on the runtime env being 4.5. I really hate this form of coding, so I was wondering if the project supports vnext yet?

Also is there a release blog or somthing I can follow/read?

@falconmick

This comment has been minimized.

Show comment
Hide comment
@falconmick

falconmick Jan 18, 2016

I tried downloading the source and checking out core-clr. But when I build I get 1117 errors... Namespace doesn't exist... So How am I supposed to build?

I tried downloading the source and checking out core-clr. But when I build I get 1117 errors... Namespace doesn't exist... So How am I supposed to build?

@arielszklarkiewicz

This comment has been minimized.

Show comment
Hide comment
@arielszklarkiewicz

arielszklarkiewicz Jan 18, 2016

Contributor

Hi,

Please try the xUnit branch in the meanwhile. You can also use the package
at https://www.nuget.org/packages/Unity-CoreClr/1.0.0-beta3.

Thanks,

Ariel

On Sun, Jan 17, 2016 at 9:19 PM, falconmick notifications@github.com
wrote:

I tried downloading the source and checking out core-clr. But when I build
I get 1117 errors... Namespace doesn't exist... So How am I supposed to
build?


Reply to this email directly or view it on GitHub
#42 (comment)
.

Contributor

arielszklarkiewicz commented Jan 18, 2016

Hi,

Please try the xUnit branch in the meanwhile. You can also use the package
at https://www.nuget.org/packages/Unity-CoreClr/1.0.0-beta3.

Thanks,

Ariel

On Sun, Jan 17, 2016 at 9:19 PM, falconmick notifications@github.com
wrote:

I tried downloading the source and checking out core-clr. But when I build
I get 1117 errors... Namespace doesn't exist... So How am I supposed to
build?


Reply to this email directly or view it on GitHub
#42 (comment)
.

@falconmick

This comment has been minimized.

Show comment
Hide comment
@falconmick

falconmick Jan 18, 2016

Cheers.

Is there any documentation at the moment for integrating with the new Dependency Injection pipeline they have?

Cheers.

Is there any documentation at the moment for integrating with the new Dependency Injection pipeline they have?

@arielszklarkiewicz

This comment has been minimized.

Show comment
Hide comment
@arielszklarkiewicz

arielszklarkiewicz Jan 18, 2016

Contributor

Not yet.

For ASP.NET MVC web applications or Web API, please add the Unity.Mvc6 package, which reference to Unity-CoreClr.

In an ASP.NET MVC application, and using the ASP.NET 5 Template for Web Application, you will tipically declare a UnityContainer property in the Startup class. Lets say a
UnityContainer _container;

In the Startup method you should instantiate it

 _container = new UnityContainer();

The ConfigureServices method is where you configure all types you need in the container and, at the bottom of the method, call the Register method of Unity.Mvc.Configuration, passing the services IServiceCollection that comes as ConfigureServices's parameter and the container.
It will look like this:

public void ConfigureServices(IServiceCollection services)
{
  ...
  services.AddMvc(); // comes with the template
  ...
  _container.RegisterInstance<ISampleInterfaceA>(new SampleClassA());
  _container.RegisterInstance<ISampleInterfaceB>(new SampleClassB());
  ...
  Unity.Mvc.Configuration.Register(services, _container);
}

Finally, add the following 2 lines to the begining of the Configure method:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
  _container.AlternativeServiceProvider = app.ApplicationServices;
  app.ApplicationServices = _container.Resolve<IServiceProvider>();
  ...
}

That's it. You should, for instance, write constructors for your controllers that expect ISampleInterfaceA and ISampleInterfaceB parameters, and they will be injected as configured.

Cheers,

Ariel

Contributor

arielszklarkiewicz commented Jan 18, 2016

Not yet.

For ASP.NET MVC web applications or Web API, please add the Unity.Mvc6 package, which reference to Unity-CoreClr.

In an ASP.NET MVC application, and using the ASP.NET 5 Template for Web Application, you will tipically declare a UnityContainer property in the Startup class. Lets say a
UnityContainer _container;

In the Startup method you should instantiate it

 _container = new UnityContainer();

The ConfigureServices method is where you configure all types you need in the container and, at the bottom of the method, call the Register method of Unity.Mvc.Configuration, passing the services IServiceCollection that comes as ConfigureServices's parameter and the container.
It will look like this:

public void ConfigureServices(IServiceCollection services)
{
  ...
  services.AddMvc(); // comes with the template
  ...
  _container.RegisterInstance<ISampleInterfaceA>(new SampleClassA());
  _container.RegisterInstance<ISampleInterfaceB>(new SampleClassB());
  ...
  Unity.Mvc.Configuration.Register(services, _container);
}

Finally, add the following 2 lines to the begining of the Configure method:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
  _container.AlternativeServiceProvider = app.ApplicationServices;
  app.ApplicationServices = _container.Resolve<IServiceProvider>();
  ...
}

That's it. You should, for instance, write constructors for your controllers that expect ISampleInterfaceA and ISampleInterfaceB parameters, and they will be injected as configured.

Cheers,

Ariel

@luizfbicalho

This comment has been minimized.

Show comment
Hide comment
@luizfbicalho

luizfbicalho Jan 25, 2016

I looked at the core-clr version, and the biggest doubt that I have is about the configuration, do you have plans to make some json configuration to use with asp.net 5?
Do you have a table of features planned for unity-coreclr and old unity? I'm not even sure if all of the actual features can be in the coreclr version.

I looked at the core-clr version, and the biggest doubt that I have is about the configuration, do you have plans to make some json configuration to use with asp.net 5?
Do you have a table of features planned for unity-coreclr and old unity? I'm not even sure if all of the actual features can be in the coreclr version.

@Hem

This comment has been minimized.

Show comment
Hide comment
@Hem

Hem Aug 24, 2016

Ariel this solution is not longer working.

  1. _container.AlternativeServiceProvider was not found.
  2. I'm receiving this error.

An exception of type 'Unity.ResolutionFailedException' occurred in Unity-CoreClr.dll but was not handled in user code

Additional information: Resolution of the dependency failed, type = "Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler", name = "(none)".

Exception occurred while: while resolving.

Exception is: ResolutionFailedException - Resolution of the dependency failed, type = "Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider", name = "(none)".

Exception occurred while: while resolving.

Exception is: ResolutionFailedException - Resolution of the dependency failed, type = "Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator[]", name = "(none)".

Exception occurred while: while resolving.

Exception is: ResolutionFailedException - Resolution of the dependency failed, type = "Microsoft.Extensions.Localization.IStringLocalizerFactory", name = "(none)".

Exception occurred while: while resolving.

Exception is: InvalidOperationException - The current type, Microsoft.Extensions.Localization.IStringLocalizerFactory, is an interface and cannot be constructed. Are you missing a type mapping?


At the time of the exception, the container was:

Resolving Microsoft.Extensions.Localization.IStringLocalizerFactory,(none)


At the time of the exception, the container was:

Resolving Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator[],(none)

Resolving Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator,Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 (mapped from Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator, Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)

Resolving parameter "modelMetadataProvider" of constructor Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator(Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider modelMetadataProvider)

  Resolving Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider,(none) (mapped from Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, (none))

  Resolving parameter "detailsProvider" of constructor Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider(Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.ICompositeMetadataDetailsProvider detailsProvider)

    Resolving Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.ICompositeMetadataDetailsProvider,(none)

At the time of the exception, the container was:

Resolving Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvokerProvider,(none) (mapped from Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider, (none))

Resolving parameter "controllerFactory" of constructor Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvokerProvider(Microsoft.AspNetCore.Mvc.Controllers.IControllerFactory controllerFactory, Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvokerCache controllerActionInvokerCache, Microsoft.AspNetCore.Mvc.Internal.IControllerArgumentBinder argumentBinder, Microsoft.Extensions.Options.IOptions`1[[Microsoft.AspNetCore.Mvc.MvcOptions, Microsoft.AspNetCore.Mvc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] optionsAccessor, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Diagnostics.DiagnosticSource diagnosticSource)

Resolving Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory,(none) (mapped from Microsoft.AspNetCore.Mvc.Controllers.IControllerFactory, (none))

Resolving parameter "propertyActivators" of constructor Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory(Microsoft.AspNetCore.Mvc.Controllers.IControllerActivator controllerActivator, System.Collections.Generic.IEnumerable`1[[Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator, Microsoft.AspNetCore.Mvc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] propertyActivators)

  Resolving System.Collections.Generic.IEnumerable`1[Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator],(none)

At the time of the exception, the container was:

Resolving Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler,(none)

Resolving parameter "actionInvokerFactory" of constructor Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler(Microsoft.AspNetCore.Mvc.Internal.IActionInvokerFactory actionInvokerFactory, Microsoft.AspNetCore.Mvc.Infrastructure.IActionSelector actionSelector, System.Diagnostics.DiagnosticSource diagnosticSource, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor actionContextAccessor)

Resolving Microsoft.AspNetCore.Mvc.Internal.ActionInvokerFactory,(none) (mapped from Microsoft.AspNetCore.Mvc.Internal.IActionInvokerFactory, (none))

Resolving parameter "actionInvokerProviders" of constructor Microsoft.AspNetCore.Mvc.Internal.ActionInvokerFactory(System.Collections.Generic.IEnumerable`1[[Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider, Microsoft.AspNetCore.Mvc.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] actionInvokerProviders)

  Resolving System.Collections.Generic.IEnumerable`1[Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider],(none)

Hem commented Aug 24, 2016

Ariel this solution is not longer working.

  1. _container.AlternativeServiceProvider was not found.
  2. I'm receiving this error.

An exception of type 'Unity.ResolutionFailedException' occurred in Unity-CoreClr.dll but was not handled in user code

Additional information: Resolution of the dependency failed, type = "Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler", name = "(none)".

Exception occurred while: while resolving.

Exception is: ResolutionFailedException - Resolution of the dependency failed, type = "Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider", name = "(none)".

Exception occurred while: while resolving.

Exception is: ResolutionFailedException - Resolution of the dependency failed, type = "Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator[]", name = "(none)".

Exception occurred while: while resolving.

Exception is: ResolutionFailedException - Resolution of the dependency failed, type = "Microsoft.Extensions.Localization.IStringLocalizerFactory", name = "(none)".

Exception occurred while: while resolving.

Exception is: InvalidOperationException - The current type, Microsoft.Extensions.Localization.IStringLocalizerFactory, is an interface and cannot be constructed. Are you missing a type mapping?


At the time of the exception, the container was:

Resolving Microsoft.Extensions.Localization.IStringLocalizerFactory,(none)


At the time of the exception, the container was:

Resolving Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator[],(none)

Resolving Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator,Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 (mapped from Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator, Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)

Resolving parameter "modelMetadataProvider" of constructor Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionaryControllerPropertyActivator(Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider modelMetadataProvider)

  Resolving Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider,(none) (mapped from Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, (none))

  Resolving parameter "detailsProvider" of constructor Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadataProvider(Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.ICompositeMetadataDetailsProvider detailsProvider)

    Resolving Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.ICompositeMetadataDetailsProvider,(none)

At the time of the exception, the container was:

Resolving Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvokerProvider,(none) (mapped from Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider, (none))

Resolving parameter "controllerFactory" of constructor Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvokerProvider(Microsoft.AspNetCore.Mvc.Controllers.IControllerFactory controllerFactory, Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvokerCache controllerActionInvokerCache, Microsoft.AspNetCore.Mvc.Internal.IControllerArgumentBinder argumentBinder, Microsoft.Extensions.Options.IOptions`1[[Microsoft.AspNetCore.Mvc.MvcOptions, Microsoft.AspNetCore.Mvc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] optionsAccessor, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Diagnostics.DiagnosticSource diagnosticSource)

Resolving Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory,(none) (mapped from Microsoft.AspNetCore.Mvc.Controllers.IControllerFactory, (none))

Resolving parameter "propertyActivators" of constructor Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory(Microsoft.AspNetCore.Mvc.Controllers.IControllerActivator controllerActivator, System.Collections.Generic.IEnumerable`1[[Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator, Microsoft.AspNetCore.Mvc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] propertyActivators)

  Resolving System.Collections.Generic.IEnumerable`1[Microsoft.AspNetCore.Mvc.Internal.IControllerPropertyActivator],(none)

At the time of the exception, the container was:

Resolving Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler,(none)

Resolving parameter "actionInvokerFactory" of constructor Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler(Microsoft.AspNetCore.Mvc.Internal.IActionInvokerFactory actionInvokerFactory, Microsoft.AspNetCore.Mvc.Infrastructure.IActionSelector actionSelector, System.Diagnostics.DiagnosticSource diagnosticSource, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.Mvc.Infrastructure.IActionContextAccessor actionContextAccessor)

Resolving Microsoft.AspNetCore.Mvc.Internal.ActionInvokerFactory,(none) (mapped from Microsoft.AspNetCore.Mvc.Internal.IActionInvokerFactory, (none))

Resolving parameter "actionInvokerProviders" of constructor Microsoft.AspNetCore.Mvc.Internal.ActionInvokerFactory(System.Collections.Generic.IEnumerable`1[[Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider, Microsoft.AspNetCore.Mvc.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]] actionInvokerProviders)

  Resolving System.Collections.Generic.IEnumerable`1[Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider],(none)
@ENikS

This comment has been minimized.

Show comment
Hide comment
@ENikS

ENikS Sep 21, 2017

Member

Duplicate of #1

Member

ENikS commented Sep 21, 2017

Duplicate of #1

@ENikS ENikS closed this Sep 21, 2017

@ENikS ENikS marked this as a duplicate of #1 Sep 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment