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

Use dependency context from all application parts when compiling views #4672

Closed
wants to merge 1 commit into from

Conversation

pranavkm
Copy link
Contributor

Fixes #4498

@pranavkm
Copy link
Contributor Author

cc @javiercn \ @rynowak

{
public void PopulateFeature(IEnumerable<ApplicationPart> parts, MetadataReferenceFeature feature)
{
var currentAssembly = GetType().GetTypeInfo().Assembly;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test site is set up so that the only AssemblyPart that was added was for the ClassLibrary that it was referencing. I added this so as to not perturb the arrangement.

@javiercn
Copy link
Member

}

var libraryPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var part in parts.OfType<AssemblyPart>())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not be casting to AssemblyPart here. Make a new interface that returns a DC and cast to that.

This way a user can plug in a custom part that returns an arbitrary DC if desired.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can make the interface return metadata references directly... not sure which is better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd have to make Mvc.Core depend on Roslyn \ DependencyModel? Is that fine by you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DependencyModel I'm not concerned about because the APM already does.... Roslyn we shouldn't do.

@rynowak
Copy link
Member

rynowak commented May 19, 2016

@pranavkm pranavkm force-pushed the prkrishn/read-more-app-parts branch 3 times, most recently from 94d42cd to 8651e71 Compare May 19, 2016 18:54
@pranavkm
Copy link
Contributor Author

🆙 📅

/// <summary>
/// Exposes a <see cref="DependencyContext"/> from an <see cref="ApplicationPart"/>.
/// </summary>
public interface IDependencyContextProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry in advance for being a jerk.

How hard is a DC to construct? Would it be better to expose a limited set of the stuff it provides from this interface instead?

I'm just asking the question. I feel like this is a good starting point at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the nicest API to work with. See https://github.com/aspnet/Mvc/pull/4672/files/8651e71758e11828e66b9175e999f938fb6a3c2e#diff-c1746f8559d5a5341fe8a1b87c65d5daL304. We could boil this down to reference paths or push the CLI to make this API easier to construct.

cc @pakrym \ @davidfowl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pranavkm: How would you like API to look like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure. Maybe a utility method that constructs it given reference paths?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pranavkm that doesn't seem entirely awful

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that might be the best, and that gets to the heart of what you might actually want to do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pakrym where does CompileLibrariesProvider live? Is that a suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javiercn Yes, I suggest to create ICompileLibrariesProvider interface instead of IDependencyContextProvider because MVC only uses CompilationLibraries from DependencyContext and in this case no new API is required to simplify dependency context creation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the interesting part of CompileLibraries is https://github.com/dotnet/cli/blob/rel/1.0.0/src/Microsoft.Extensions.DependencyModel/CompilationLibrary.cs#L39 that we use on https://github.com/aspnet/Mvc/pull/4672/files#diff-ab147a7292f31e46ebc6b39f1df7480bR49

Maybe we can have our own DTO with the interesting parts of compilelibrary and the resolved paths? I think that strikes a good balance. I think something like ApplicationReference { Name, Version and Paths } will be enough

@rynowak @pranavkm Thoughts?

Copy link
Contributor Author

@pranavkm pranavkm May 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it basically be the same type at that point?

Edit: We really don't need the type at all that point. We could simply expose a sequence of reference paths (I suggested that earlier).

@pranavkm pranavkm force-pushed the prkrishn/read-more-app-parts branch from 8651e71 to 19d5d1c Compare May 20, 2016 23:52
@pranavkm
Copy link
Contributor Author

🆙 📅

@javiercn
Copy link
Member

:shipit: when @rynowak is happy

@gdau
Copy link

gdau commented May 23, 2016

Noted a small typo - GetCompilatonLibraries should be GetCompilationLibraries :)

@pranavkm
Copy link
Contributor Author

Nice catch @gdau

@pranavkm pranavkm force-pushed the prkrishn/read-more-app-parts branch from 19d5d1c to 18124db Compare May 23, 2016 17:27
@pranavkm
Copy link
Contributor Author

Ping @rynowak

/// <summary>
/// Gets the sequence of <see cref="CompilationLibrary"/> instances.
/// </summary>
IReadOnlyList<CompilationLibrary> GetCompilationLibraries();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ICompileLibrariesProvider <-> GetCompilationLibraries

The nouns aren't really the same between these. Should it be ICompileLibrariesProvider?

Copy link
Contributor Author

@pranavkm pranavkm May 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean ICompilationLibrariesProvider?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we exposing this as a public API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent is to allow users to add additional compilation libraries

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show me a sample of that? Why wouldn't they just add a metadata reference?

Copy link
Member

@rynowak rynowak May 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't they just add a metadata reference?

You can ask this question about 100% of the application parts feature, but we still lots of requests for something like this and we still ended up building it. You can solve all of the problems that application parts solve by just referencing everything from one project, but users have come up with plenty of cases where they don't want to do that.

As @pranavkm said this is here so you can author a custom part and have control over which assemblies are included as references. Providing interfaces for the various capabilities is part of the design of parts.

Why would you do this? Well I suppose you could use it to work around the bug we have where a .csproj isn't part of the dependency graph :trollface:

@rynowak
Copy link
Member

rynowak commented May 24, 2016

:shipit:

@pranavkm pranavkm closed this May 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants