I have multiple projects kind of multiple microservices, each microservice contain multiple projects with an api project.
What I want is to get all projects assemblies (load all application assemblies dynamically ) into a db or a json file or whatever . After that I’ll retrieve from each assembly api project list of all controllers. What I have done until now, is to get all controllers just for one assembly for one microservice (project).
This my code :
var result = Assembly.GetExecutingAssembly()
.GetTypes()
.Where(type => typeof(Controller).IsAssignableFrom(type))
.SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
.Where(m => !m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Any())
.GroupBy(x => x.DeclaringType.Name) //just to get each action belong to correspondent controller
.Select(x => new
{
Controller = x.Key,
Actions = x.Select(s => s.Name).ToList()
})
.ToList();
Thanks in advance.