Skip to content

Commit

Permalink
Move ConstructionBinding from an annotation to an interface
Browse files Browse the repository at this point in the history
Move OnModelFinalized invocation to ModelRuntimeInitializer

Part of #19213
  • Loading branch information
AndriySvyryd committed Feb 5, 2021
1 parent b848377 commit a1e37a6
Show file tree
Hide file tree
Showing 66 changed files with 1,133 additions and 615 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public virtual CosmosOptionsExtension WithConnectionString([CanBeNull] string? c
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string? DatabaseName
=> _databaseName;
public virtual string DatabaseName
=> _databaseName!;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Diagnostics.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Design;
using Microsoft.EntityFrameworkCore.Migrations.Internal;
Expand Down
28 changes: 20 additions & 8 deletions src/EFCore.Design/Design/Internal/DesignTimeServicesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,24 @@ public class DesignTimeServicesBuilder
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IServiceProvider Build([NotNull] DbContext context)
{
Check.NotNull(context, nameof(context));
=> CreateServiceCollection(Check.NotNull(context, nameof(context))).BuildServiceProvider();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IServiceCollection CreateServiceCollection([NotNull] DbContext context)
{
var services = new ServiceCollection()
.AddEntityFrameworkDesignTimeServices(_reporter)
.AddDbContextDesignTimeServices(context);
var provider = context.GetService<IDatabaseProvider>().Name;
ConfigureProviderServices(provider, services);
ConfigureReferencedServices(services, provider);
ConfigureUserServices(services);

return services.BuildServiceProvider();
return services;
}

/// <summary>
Expand All @@ -72,16 +78,22 @@ public virtual IServiceProvider Build([NotNull] DbContext context)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IServiceProvider Build([NotNull] string provider)
{
Check.NotEmpty(provider, nameof(provider));
=> CreateServiceCollection(Check.NotEmpty(provider, nameof(provider))).BuildServiceProvider();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual IServiceCollection CreateServiceCollection([NotNull] string provider)
{
var services = new ServiceCollection()
.AddEntityFrameworkDesignTimeServices(_reporter, GetApplicationServices);
ConfigureProviderServices(provider, services, throwOnError: true);
ConfigureReferencedServices(services, provider);
ConfigureUserServices(services);

return services.BuildServiceProvider();
return services;
}

private IServiceProvider GetApplicationServices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class RelationalScaffoldingModelFactory : IScaffoldingModelFactory
private readonly ICSharpUtilities _cSharpUtilities;
private readonly IScaffoldingTypeMapper _scaffoldingTypeMapper;
private readonly LoggingDefinitions _loggingDefinitions;
private readonly IModelRuntimeInitializer _modelRuntimeInitializer;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -57,21 +59,24 @@ public class RelationalScaffoldingModelFactory : IScaffoldingModelFactory
[NotNull] IPluralizer pluralizer,
[NotNull] ICSharpUtilities cSharpUtilities,
[NotNull] IScaffoldingTypeMapper scaffoldingTypeMapper,
[NotNull] LoggingDefinitions loggingDefinitions)
[NotNull] LoggingDefinitions loggingDefinitions,
[NotNull] IModelRuntimeInitializer modelRuntimeInitializer)
{
Check.NotNull(reporter, nameof(reporter));
Check.NotNull(candidateNamingService, nameof(candidateNamingService));
Check.NotNull(pluralizer, nameof(pluralizer));
Check.NotNull(cSharpUtilities, nameof(cSharpUtilities));
Check.NotNull(scaffoldingTypeMapper, nameof(scaffoldingTypeMapper));
Check.NotNull(loggingDefinitions, nameof(loggingDefinitions));
Check.NotNull(modelRuntimeInitializer, nameof(modelRuntimeInitializer));

_reporter = reporter;
_candidateNamingService = candidateNamingService;
_pluralizer = pluralizer;
_cSharpUtilities = cSharpUtilities;
_scaffoldingTypeMapper = scaffoldingTypeMapper;
_loggingDefinitions = loggingDefinitions;
_modelRuntimeInitializer = modelRuntimeInitializer;
}

/// <summary>
Expand Down Expand Up @@ -108,7 +113,7 @@ public virtual IModel Create(DatabaseModel databaseModel, ModelReverseEngineerOp

VisitDatabaseModel(modelBuilder, databaseModel);

return modelBuilder.FinalizeModel();
return _modelRuntimeInitializer.Initialize(modelBuilder.FinalizeModel(), null);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Proxies/Proxies/Internal/IProxyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface IProxyFactory
/// </summary>
Type CreateProxyType(
[NotNull] ProxiesOptionsExtension options,
[NotNull] IEntityType entityType);
[NotNull] IReadOnlyEntityType entityType);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down

0 comments on commit a1e37a6

Please sign in to comment.