Skip to content
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

Assembly Catalog #2025

Closed
wants to merge 2 commits into from
Closed

Assembly Catalog #2025

wants to merge 2 commits into from

Conversation

galvesribeiro
Copy link
Member

Initial implementation of IAssemblyCatalog.

This is part of the move to support .Net Core on #368 by removing the the dependency on AppDomains.

The default catalog implementation (AssemblyCatalog) requires the developer to set the assemblies list by XML <Assemblies> or code config. Later on, this implementation can be replaced by using DI.

Some changes were required on codegen in order to support it. So now, there is no scan for assemblies on a specific folder anymore. You have to inform the assembly list that needs to be processed for runtime codegen.

private static void OnAssemblyLoad(object sender, AssemblyLoadEventArgs args)
{
AssemblyProcessor.ProcessAssembly(args.LoadedAssembly);
AssemblyProcessor.ProcessAssemblies(catalog.GetAssemblies());
Copy link
Member

Choose a reason for hiding this comment

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

Is there a nice way that we can move this work out of the constructor and into another method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@jdom jdom added this to the CoreCLR milestone Aug 8, 2016
@jdom
Copy link
Member

jdom commented Aug 8, 2016

I wonder whether we should be emulating MVC Core with its ApplicationParts it uses for stuff such as finding controllers or TagHelpers

Without too much familiarity with their implementation, I believe both systems are trying to do the same thing, so I'd lean to trust that the MVC is very familiar with how the new tooling works (which is the reason we are proactively changing this in preparation to our port, but not really testing it yet in that environment). Maybe it doesn't make sense, but it's worth a small research at least.

@galvesribeiro
Copy link
Member Author

Ok, updated with most of the feedback.

@jdom, I'm been looking the the AspNet Core parts and tagHelpers as you suggested... I still think that it will fall in the same case as MEF... A bunch of code for small win. I still thinking that now we removed all that bunch of code for scanning and we are close to what people asked which is provide a list of assemblies either by code or XML or, by replacing some sort of catalog implementation (we will add DI support to it later on).

@adamhathcock
Copy link

This may be relevant: https://github.com/khellang/Scrutor

This is a nice way of scanning assemblies and registering them with IServiceCollection I like using it anyway.


public AssemblyCatalog()
{
logger = LogManager.GetLogger("AssemblyCatalog", LoggerType.Provider);
Copy link
Contributor

Choose a reason for hiding this comment

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

nameof?

@sergeybykov
Copy link
Contributor

"Project file does not exist." Hmm...

@galvesribeiro
Copy link
Member Author

I think it is .net CLI not installed...


namespace Orleans.Runtime
{
public class AssemblyCatalog : IAssemblyCatalog
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it were useful to separate the handling logic from the traversal logic in creating something like

public static IEnumerable<T> AsDepthFirst<T>(this IEnumerable<T> elements, Func<T, IEnumerable<T>> descendantSelector)
{
    var stack = new Stack<T>(elements);
    while(stack.Any())
    {
            var next = stack.Pop();
            yield return next;
            foreach(var descendant in descendantSelector(next))
            {
                stack.Push(descendant);
            }
        }
    }
}

Then it would be possible to do something like rootAssemblies.AsDepthFirst(assembly => assembly.GetReferencedAssemblies().Where(i => !blacklist.Contains(i.Name));. This likely varies here, taken from the Gitter discussion. This wouldn't certainly cause stack overflow either.

Copy link
Member Author

Choose a reason for hiding this comment

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

@veikkoeeva can you put a PR to this branch? Appreciate that. Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

@galvesribeiro How long can this branch wait? :-P One the first though this modification would seem sensible, but would require one to suss out the details with APIs. I'm glad if you consider this and find a way, or someone else, but as of myself, well, you'd need to wait a week or two at minimum. Though if this makes sense, I, you, or someone else, could do a PR later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. The way it is today may not be the 10th wonder now but it does what is suppose to do. So I think we can enhance it later. What matter is the interface and its usage. The catalog implementation itself can change anytime.

Copy link
Contributor

Choose a reason for hiding this comment

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

There might be changes to the catalog interface too, but I'd be surprised if they couldn't be backawards compatible if needed.

@jdom
Copy link
Member

jdom commented Aug 26, 2016

@dotnet-bot test this please
(trying to see whether Jenkins can build with dotnet cli. Most likely it will fail without further configuration)

@adamhathcock
Copy link

Any chance this is on track to go in? This would likely help clean up a lot of the .NET Core stuff and i'd still like to help :)

@jdom
Copy link
Member

jdom commented Sep 2, 2016

Yes, I'm actually really close to pushing some branches related to core to the main repo (see my repo if interested). I found a way to not migrate to dotnet cli for now (and hence we can sill use our msbuild tasks, at least until the new tooling RTMs). I might start reviewing this on Monday, but feel free to review it yourself and accelerate this. Also, if you have experience with asm scanning in aspnet, then your input to whether it applies here too would be useful.

@adamhathcock
Copy link

Cool. I'll wait for a pull request or something as hunting around for the code doesn't feel like I'm finding the right thing.

I have two .NET Core projects in prod (one using containers!). One uses global assembly scanning with Microsoft.Extensions.DependencyModel the other just picks assemblies and scans them with Scrutor like I linked above.

}
}
return null;
}

private static Assembly MatchWithLoadedAssembly(AssemblyName searchFor, AppDomain appDomain)
{
return
return
Copy link
Contributor

Choose a reason for hiding this comment

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

is this function still being used ? I think we are dropping using AppDomain to scan assemblies.
Just a little confused.

Copy link
Contributor

@veikkoeeva veikkoeeva Sep 17, 2016

Choose a reason for hiding this comment

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

@xiazen I wonder does that mean we support both as per #2145. There was a bit of discussion if the AppDomain could be shimmed ("polyfilled") at https://gitter.im/dotnet/orleans?at=57b6079287f779f0690a9fca – also some NETStandard code on assembly loading (that likely doesn't work correctly).

Copy link
Member Author

Choose a reason for hiding this comment

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

@xiazen You are correct. This thing shouldn't be used anymore. I'll get back to it later on. Thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

@veikkoeeva I think this PR is about removing dependency on AppDomain to move to support .Net Core, which is part of #2145 . That's why I get confused.

About shimmed AppDomain, it might accelate our process on going to .Net Core. But it might also confuse people with AppDomain in .Net. I'm slightly leaning in the direction to not create that shimmed AppDomainclass. :)

Copy link
Member

Choose a reason for hiding this comment

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

hehe, funny that this was mentioned, but yes, until Assembly loading gets fixed, I'm introducing a AppDomain shim for now, otherwise there is no way I can get help fixing all the porting holes we currently have, and would have to spend a lot of time fixing every build break in the correct manner myself until I can get help with it. A PR is coming really soon.

Copy link
Contributor

Choose a reason for hiding this comment

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

haha. well I'm fine with it being there temporarily, just for an intermediate step for us to go to coreclr.

@sergeybykov
Copy link
Contributor

We are using bits and pieces of this PR as part of the 2.0 work, but won't merge it as a whole. So I'm closing it to avoid confusion.

@sergeybykov sergeybykov closed this Jan 9, 2017
@galvesribeiro galvesribeiro deleted the assembly-catalog branch January 9, 2017 17:13
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
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.

9 participants