Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Add overload to AddControllerAsServices that uses the default controller discovery logic #4014

Closed
davidfowl opened this issue Jan 29, 2016 · 9 comments
Assignees
Milestone

Comments

@davidfowl
Copy link
Member

It should use the default controller discovery logic baked into these

if (DnxPlatformServices.Default?.LibraryManager != null)
{
services.TryAddTransient<IAssemblyProvider, DefaultAssemblyProvider>();
}
else
{
services.TryAddTransient<IAssemblyProvider, DependencyContextAssemblyProvider>();
}
services.

@davidfowl davidfowl changed the title Add overload to AddControllerAsServices that uses the default MVC discovery logic Add overload to AddControllerAsServices that uses the default controller discovery logic Jan 30, 2016
@khellang
Copy link
Contributor

khellang commented Feb 5, 2016

To be clear, this pretty much means a single call to

services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());

Because the DefaultControllerTypeProvider already uses IAssemblyProvider to get to the assemblies, right?

@khellang
Copy link
Contributor

khellang commented Feb 5, 2016

Oh, and the controller type itself has to be registered in some way, DUH.

How do you get a registered IAssemblyProvider instance without building a service provider from the services?

Isn't this a bit of chicken and egg? You need to resolve from the container in order to add to it? 😄

@rynowak
Copy link
Member

rynowak commented Feb 5, 2016

Isn't this a bit of chicken and egg? You need to resolve from the container in order to add to it?

Nah, we just assume the default type provider if you're using any of these methods. If you need to do something different these methods are only like 5 lines of code so write your own.

@khellang
Copy link
Contributor

khellang commented Feb 5, 2016

Nah, we just assume the default type provider if you're using any of these methods.

And what is the default going forward? DefaultAssemblyProvider or DependencyContextAssemblyProvider?

@rynowak
Copy link
Member

rynowak commented Feb 5, 2016

I thought we were talking about the IControllerTypeProvider???

DependencyContextAssemblyProvider will be the default once we transition to .net cli

@khellang
Copy link
Contributor

khellang commented Feb 5, 2016

Basically, you want to ask the IAssemblyProvider for assemblies and pass those to the AddControllersAsServices(IEnumerable<Assembly>) overload, which internally uses DefaultControllerTypeProvider 😄

@danroth27 danroth27 added this to the 1.0.0-rc2 milestone Feb 24, 2016
@danroth27
Copy link
Member

Should this behavior actually be the default?

@davidfowl
Copy link
Member Author

That came up but it's actually really hard to remove it if you don't want that behavior by default. You basically have to reverse engineer the controller type provider and remove services

@rynowak
Copy link
Member

rynowak commented Mar 3, 2016

Iterating on design in this area - #4089

javiercn added a commit that referenced this issue Mar 30, 2016
…efault controller discovery logic.

* Added ControllerFeature and ControllerFeatureProvider to perform controller discovery.
* Changed controller discovery to use application parts.
* Changed ControllerActionDescriptorProvider to make use of Application parts.
* Simplified AddControllerAsServices to not accept any parameter and perform
  controller discovery through the ApplicationPartManager in the IMvcBuilder
  and IMvcCoreBuilder. Assemblies should be added to the ApplicationPartManager
  in order to discover controllers in them.
javiercn added a commit that referenced this issue Mar 31, 2016
…efault controller discovery logic.

* Added ControllerFeature and ControllerFeatureProvider to perform controller discovery.
* Changed controller discovery to use application parts.
* Changed ControllerActionDescriptorProvider to make use of Application parts.
* Simplified AddControllerAsServices to not accept any parameter and perform
  controller discovery through the ApplicationPartManager in the IMvcBuilder
  and IMvcCoreBuilder. Assemblies should be added to the ApplicationPartManager
  in order to discover controllers in them.
javiercn added a commit that referenced this issue Mar 31, 2016
…efault controller discovery logic.

* Added ControllerFeature and ControllerFeatureProvider to perform controller discovery.
* Changed controller discovery to use application parts.
* Changed ControllerActionDescriptorProvider to make use of Application parts.
* Simplified AddControllerAsServices to not accept any parameter and perform
  controller discovery through the ApplicationPartManager in the IMvcBuilder
  and IMvcCoreBuilder. Assemblies should be added to the ApplicationPartManager
  in order to discover controllers in them.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants