Skip to content

Commit 4bb71d2

Browse files
author
liguoliang
committed
延迟加载程序集
1 parent b192933 commit 4bb71d2

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/DotNetCoreRpc.Server/ServerServiceCollectionExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ namespace DotNetCoreRpc.Server
66
{
77
public static class ServiceCollectionExtensions
88
{
9-
public static IServiceCollection AddDotNetCoreRpcServer(this IServiceCollection services, Action<RpcServerOptions> options)
9+
public static IServiceCollection AddDotNetCoreRpcServer(this IServiceCollection services, Action<RpcServerOptions> options = null)
1010
{
1111
RpcServerOptions rpcServerOptions = new RpcServerOptions();
12-
options.Invoke(rpcServerOptions);
12+
if (options != null)
13+
{
14+
options.Invoke(rpcServerOptions);
15+
}
16+
1317
services.TryAddSingleton(rpcServerOptions);
1418
return services;
1519
}

src/DotNetCoreRpc.Server/ServiceTypeCollection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace DotNetCoreRpc.Server
1010
internal class ServiceTypeCollection
1111
{
1212
private readonly ConcurrentDictionary<string, Type> _serviceTypes = new ConcurrentDictionary<string, Type>();
13-
private readonly Assembly[] _assemblies = AppDomain.CurrentDomain.GetAssemblies();
13+
private readonly Lazy<Assembly[]> _assemblies = new Lazy<Assembly[]>(() => AppDomain.CurrentDomain.GetAssemblies(), true);
1414

1515
internal Type this[string serviceName]
1616
{
@@ -20,7 +20,7 @@ internal Type this[string serviceName]
2020
internal Type GetServiceType(string serviceName)
2121
{
2222
return _serviceTypes.GetOrAdd(serviceName, typeName => {
23-
Type serviceType = _assemblies.Select(a => a.GetType(typeName)).FirstOrDefault(t => t != null);
23+
Type serviceType = _assemblies.Value.Select(a => a.GetType(typeName)).FirstOrDefault(t => t != null);
2424

2525
if (serviceType == null)
2626
{

0 commit comments

Comments
 (0)