-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate more of network initialization
- Loading branch information
Showing
37 changed files
with
613 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/Nethermind/Nethermind.Config/ConfigRegistrationSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Autofac; | ||
using Autofac.Core; | ||
using Autofac.Core.Activators.Delegate; | ||
using Autofac.Core.Lifetime; | ||
using Autofac.Core.Registration; | ||
|
||
namespace Nethermind.Config; | ||
|
||
/// <summary> | ||
/// Dynamically resolve IConfig<T> | ||
/// </summary> | ||
public class ConfigRegistrationSource : IRegistrationSource | ||
{ | ||
public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Func<Service, IEnumerable<ServiceRegistration>> registrationAccessor) | ||
{ | ||
IServiceWithType swt = service as IServiceWithType; | ||
if (swt == null || !typeof(IConfig).IsAssignableFrom(swt.ServiceType)) | ||
{ | ||
// It's not a request for the base handler type, so skip it. | ||
return Enumerable.Empty<IComponentRegistration>(); | ||
} | ||
|
||
// Dynamically resolve IConfig | ||
ComponentRegistration registration = new ComponentRegistration( | ||
Guid.NewGuid(), | ||
new DelegateActivator(swt.ServiceType, (c, p) => | ||
{ | ||
IConfigProvider configProvider = c.Resolve<IConfigProvider>(); | ||
object config = typeof(IConfigProvider) | ||
.GetMethod("GetConfig") | ||
.MakeGenericMethod(swt.ServiceType) | ||
.Invoke(configProvider, new object[] { }); | ||
return config; | ||
}), | ||
new RootScopeLifetime(), | ||
InstanceSharing.Shared, | ||
InstanceOwnership.OwnedByLifetimeScope, | ||
new[] { service }, | ||
new Dictionary<string, object>()); | ||
|
||
return new IComponentRegistration[] { registration }; | ||
} | ||
|
||
public bool IsAdapterForIndividualComponents => false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.