Skip to content

Commit

Permalink
Updated code for better isolation of component usage and registration…
Browse files Browse the repository at this point in the history
… behind Extensions feature.
  • Loading branch information
gmcelhanon committed Nov 19, 2024
1 parent abc03a1 commit 0ea3fce
Show file tree
Hide file tree
Showing 9 changed files with 1,571 additions and 1,610 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,6 @@ protected override void Load(ContainerBuilder builder)
.As<IResourceValidator>()
.SingleInstance();

builder.RegisterType<NoEntityExtensionsFactory>()
.As<IEntityExtensionsFactory>()
.PreserveExistingDefaults()
.SingleInstance();

builder.RegisterType<MappingContractProvider>()
.As<IMappingContractProvider>()
.SingleInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using EdFi.Ods.Common.Infrastructure.Extensibility;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Api.Security.AuthorizationStrategies.Relationships;
using EdFi.Ods.Common.Dependencies;

namespace EdFi.Ods.Api.Container.Modules
{
Expand Down Expand Up @@ -47,6 +48,13 @@ public override void ApplyConfigurationSpecificRegistrations(ContainerBuilder bu
.As<IEntityExtensionRegistrar>()
.SingleInstance();

// Set feature-specific static resolvers
builder.RegisterBuildCallback(container =>
{
GeneratedArtifactStaticDependencies.Resolvers.Set(container.Resolve<IEntityExtensionsFactory>);
GeneratedArtifactStaticDependencies.Resolvers.Set(container.Resolve<IEntityExtensionRegistrar>);
});

installedExtensionAssemblies.ForEach(
assembly =>
{
Expand Down
3 changes: 0 additions & 3 deletions Application/EdFi.Ods.Api/Startup/OdsStartupBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ void SetStaticResolvers()
GeneratedArtifactStaticDependencies.Resolvers.Set(() => (StringComparer) Container.Resolve<IDatabaseEngineSpecificEqualityComparerProvider<string>>().GetEqualityComparer());
GeneratedArtifactStaticDependencies.Resolvers.Set(() => Container.Resolve<IDescriptorResolver>());
GeneratedArtifactStaticDependencies.Resolvers.Set(() => Container.Resolve<IContextProvider<DataPolicyException>>());
GeneratedArtifactStaticDependencies.Resolvers.Set(() => Container.Resolve<IEntityExtensionRegistrar>());
GeneratedArtifactStaticDependencies.Resolvers.Set(() => Container.Resolve<ISessionFactoryImplementor>());

// netcore has removed the claims principal from the thread, to be on the controller.
Expand All @@ -454,8 +453,6 @@ void SetStaticResolvers()
() => Container.Resolve<IResourceModelProvider>()
.GetResourceModel());

EntityExtensionsFactory.Instance = Container.Resolve<IEntityExtensionsFactory>();

// Set NHibernate to use Autofac to resolve its dependencies
NHibernate.Cfg.Environment.ObjectsFactory = new NHibernateAutofacObjectsFactory(Container);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static class GeneratedArtifactStaticDependencies
private static Lazy<StringComparer> _databaseEngineSpecificStringComparer;
private static Lazy<IDescriptorResolver> _descriptorResolver;
private static Lazy<IEntityExtensionRegistrar> _entityExtensionRegistrar;
private static Lazy<IEntityExtensionsFactory> _entityExtensionsFactory;
private static Lazy<ISessionFactoryImplementor> _sessionFactory;

public static IAuthorizationContextProvider AuthorizationContextProvider => _authorizationContextProvider?.Value;
Expand All @@ -49,6 +50,7 @@ public static class GeneratedArtifactStaticDependencies
public static StringComparer DatabaseEngineSpecificStringComparer => _databaseEngineSpecificStringComparer?.Value;
public static IDescriptorResolver DescriptorResolver => _descriptorResolver?.Value;
public static IEntityExtensionRegistrar EntityExtensionRegistrar => _entityExtensionRegistrar?.Value;
public static IEntityExtensionsFactory EntityExtensionsFactory => _entityExtensionsFactory?.Value;
public static ISessionFactoryImplementor SessionFactory => _sessionFactory?.Value;

/// <summary>
Expand Down Expand Up @@ -122,6 +124,11 @@ public static void Set(Func<IEntityExtensionRegistrar> resolver)
_entityExtensionRegistrar = new Lazy<IEntityExtensionRegistrar>(resolver);
}

public static void Set(Func<IEntityExtensionsFactory> resolver)
{
_entityExtensionsFactory = new Lazy<IEntityExtensionsFactory>(resolver);
}

public static void Set(Func<ISessionFactoryImplementor> resolver)
{
_sessionFactory = new Lazy<ISessionFactoryImplementor>(resolver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ public EntityExtensionsFactory(IEntityExtensionRegistrar entityExtensionRegistra
_entityExtensionRegistrar = entityExtensionRegistrar;
}

/// <summary>
/// Gets the singleton instance of the factory for creating aggregate and entity extensions.
/// </summary>
/// <remarks>This property is used to make the factory available to the entity classes during initialization since they are not managed by the IoC container.</remarks>
public static IEntityExtensionsFactory Instance { get; set; }

/// <summary>
/// Creates an <see cref="System.Collections.IDictionary"/> containing new instances of the registered entity extension types
/// for the Ed-Fi "core" entity specified by <typeparamref name="TEntity"/>.
Expand Down

This file was deleted.

Loading

0 comments on commit 0ea3fce

Please sign in to comment.