Skip to content

Commit

Permalink
Merge pull request #389 from Cysharp/feature/ExcludeWellKnownAssemblies
Browse files Browse the repository at this point in the history
Exclude well-known assemblies from automatic discovery of services.
  • Loading branch information
neuecc authored Dec 14, 2020
2 parents e5a58d1 + bfddfef commit 5d8932a
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/MagicOnion.Server/MagicOnionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,44 @@ public static MagicOnionServiceDefinition BuildServerServiceDefinition(IServiceP
/// <param name="options">The options for MagicOnion server</param>
public static MagicOnionServiceDefinition BuildServerServiceDefinition(IServiceProvider serviceProvider, MagicOnionOptions options)
{
return BuildServerServiceDefinition(serviceProvider, AppDomain.CurrentDomain.GetAssemblies(), options);
// NOTE: Exclude well-known system assemblies from automatic discovery of services.
var wellKnownIgnoreAssemblies = new[]
{
"netstandard",
"System.*",
"Microsoft.Win32.*",
"Microsoft.Extensions.*",
"Microsoft.AspNetCore",
"Microsoft.AspNetCore.*",
"Grpc.*",
"MessagePack",
"MessagePack.*",
"MagicOnion.Server",
"MagicOnion.Server.*",
"MagicOnion.Client",
"MagicOnion.Client.*", // MagicOnion.Client.DynamicClient (MagicOnionClient.Create<T>)
"MagicOnion.Abstractions",
"MagicOnion.Shared",
};

var assemblies = AppDomain.CurrentDomain.GetAssemblies()
.Where(x =>
{
return !wellKnownIgnoreAssemblies.Any(y =>
{
if (y.EndsWith('*'))
{
return x.GetName().Name!.StartsWith(y.Substring(0, y.Length - 1));
}
else
{
return x.GetName().Name == y;
}
});
})
.ToArray();

return BuildServerServiceDefinition(serviceProvider, assemblies, options);
}

/// <summary>
Expand Down

0 comments on commit 5d8932a

Please sign in to comment.