Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing design-time services #24362

Merged
1 commit merged into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

using System;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Design.Internal;
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.Internal;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Migrations.Design;
using Microsoft.EntityFrameworkCore.Migrations.Internal;
Expand Down Expand Up @@ -50,37 +53,49 @@ public static IServiceCollection AddEntityFrameworkDesignTimeServices(
.AddSingleton<CSharpMigrationOperationGeneratorDependencies>()
.AddSingleton<CSharpMigrationsGeneratorDependencies>()
.AddSingleton<CSharpSnapshotGeneratorDependencies>()
.AddSingleton<MigrationsCodeGeneratorDependencies>()
.AddSingleton<ModelCodeGeneratorDependencies>()
.AddSingleton<ProviderCodeGeneratorDependencies>()
.AddSingleton<TypeMappingSourceDependencies>()
.AddSingleton<RelationalTypeMappingSourceDependencies>()
.AddSingleton<ValueConverterSelectorDependencies>()
.AddSingleton<DiagnosticSource>(new DiagnosticListener(DbLoggerCategory.Name))
.AddSingleton<IAnnotationCodeGenerator, AnnotationCodeGenerator>()
.AddSingleton<ICandidateNamingService, CandidateNamingService>()
.AddSingleton<IConstructorBindingFactory, ConstructorBindingFactory>()
.AddSingleton<ICSharpDbContextGenerator, CSharpDbContextGenerator>()
.AddSingleton<ICSharpEntityTypeGenerator, CSharpEntityTypeGenerator>()
.AddSingleton<ICSharpHelper, CSharpHelper>()
.AddSingleton<ICSharpMigrationOperationGenerator, CSharpMigrationOperationGenerator>()
.AddSingleton<ICSharpSnapshotGenerator, CSharpSnapshotGenerator>()
.AddSingleton<ICSharpUtilities, CSharpUtilities>()
.AddSingleton<IDbContextLogger, NullDbContextLogger>()
.AddSingleton(typeof(IDiagnosticsLogger<>), typeof(DiagnosticsLogger<>))
.AddSingleton<IInterceptors, Interceptors>()
.AddSingleton<DiagnosticSource>(new DiagnosticListener(DbLoggerCategory.Name))
.AddSingleton<ILoggingOptions, LoggingOptions>()
.AddSingleton<IMemberClassifier, MemberClassifier>()
.AddSingleton<IMigrationsCodeGenerator, CSharpMigrationsGenerator>()
.AddSingleton<IMigrationsCodeGeneratorSelector, MigrationsCodeGeneratorSelector>()
.AddSingleton<IModelCodeGenerator, CSharpModelGenerator>()
.AddSingleton<IModelCodeGeneratorSelector, ModelCodeGeneratorSelector>()
.AddSingleton<IAnnotationCodeGenerator, AnnotationCodeGenerator>()
.AddSingleton<IModelRuntimeInitializer, ModelRuntimeInitializer>()
.AddSingleton<IModelValidator, RelationalModelValidator>()
.AddSingleton<INamedConnectionStringResolver>(
new DesignTimeConnectionStringResolver(applicationServiceProviderAccessor))
.AddSingleton(reporter)
.AddSingleton<IParameterBindingFactories, ParameterBindingFactories>()
.AddSingleton<IPluralizer, HumanizerPluralizer>()
.AddSingleton<IPropertyParameterBindingFactory, PropertyParameterBindingFactory>()
.AddSingleton<IRegisteredServices>(new RegisteredServices(services.Select(s => s.ServiceType)))
.AddSingleton<IReverseEngineerScaffolder, ReverseEngineerScaffolder>()
.AddSingleton<IScaffoldingModelFactory, RelationalScaffoldingModelFactory>()
.AddSingleton<IScaffoldingTypeMapper, ScaffoldingTypeMapper>()
.AddSingleton<ITypeMappingSource>(p => p.GetService<IRelationalTypeMappingSource>())
.AddSingleton<IValueConverterSelector, ValueConverterSelector>()
.AddSingleton<IDbContextLogger, NullDbContextLogger>()
.AddSingleton<MigrationsCodeGeneratorDependencies>()
.AddSingleton<ModelCodeGeneratorDependencies>()
.AddSingleton<ModelRuntimeInitializerDependencies>()
.AddSingleton<ModelValidatorDependencies>()
.AddSingleton<ProviderCodeGeneratorDependencies>()
.AddSingleton<RelationalModelValidatorDependencies>()
.AddSingleton<RelationalTypeMappingSourceDependencies>()
.AddSingleton<RuntimeModelDependencies>()
.AddSingleton<TypeMappingSourceDependencies>()
.AddSingleton<ValueConverterSelectorDependencies>()
.AddTransient<MigrationsScaffolderDependencies>()
.AddTransient<IMigrationsScaffolder, MigrationsScaffolder>()
.AddTransient<ISnapshotModelProcessor, SnapshotModelProcessor>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.SqlServer.Diagnostics.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Metadata.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal;
using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;

#nullable enable

[assembly: DesignTimeProviderServices("Microsoft.EntityFrameworkCore.SqlServer.Design.Internal.SqlServerDesignTimeServices")]

namespace Microsoft.EntityFrameworkCore.SqlServer.Design.Internal
{
/// <summary>
Expand All @@ -30,10 +36,11 @@ public class SqlServerDesignTimeServices : IDesignTimeServices
/// </summary>
public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
=> serviceCollection
.AddSingleton<LoggingDefinitions, SqlServerLoggingDefinitions>()
.AddSingleton<IRelationalTypeMappingSource, SqlServerTypeMappingSource>()
.AddSingleton<IAnnotationCodeGenerator, SqlServerAnnotationCodeGenerator>()
.AddSingleton<IDatabaseModelFactory, SqlServerDatabaseModelFactory>()
.AddSingleton<IModelValidator, SqlServerModelValidator>()
.AddSingleton<IProviderConfigurationCodeGenerator, SqlServerCodeGenerator>()
.AddSingleton<IAnnotationCodeGenerator, SqlServerAnnotationCodeGenerator>();
.AddSingleton<IRelationalTypeMappingSource, SqlServerTypeMappingSource>()
.AddSingleton<LoggingDefinitions, SqlServerLoggingDefinitions>();
}
}
8 changes: 0 additions & 8 deletions src/EFCore.SqlServer/Properties/AssemblyInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.Sqlite.Diagnostics.Internal;
using Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal;
using Microsoft.EntityFrameworkCore.Sqlite.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Sqlite.Scaffolding.Internal;
using Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;

#nullable enable

[assembly: DesignTimeProviderServices("Microsoft.EntityFrameworkCore.Sqlite.Design.Internal.SqliteDesignTimeServices")]

namespace Microsoft.EntityFrameworkCore.Sqlite.Design.Internal
{
/// <summary>
Expand All @@ -30,10 +36,11 @@ public class SqliteDesignTimeServices : IDesignTimeServices
/// </summary>
public virtual void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
=> serviceCollection
.AddSingleton<LoggingDefinitions, SqliteLoggingDefinitions>()
.AddSingleton<IRelationalTypeMappingSource, SqliteTypeMappingSource>()
.AddSingleton<IAnnotationCodeGenerator, AnnotationCodeGenerator>()
.AddSingleton<IDatabaseModelFactory, SqliteDatabaseModelFactory>()
.AddSingleton<IModelValidator, SqliteModelValidator>()
.AddSingleton<IProviderConfigurationCodeGenerator, SqliteCodeGenerator>()
.AddSingleton<IAnnotationCodeGenerator, AnnotationCodeGenerator>();
.AddSingleton<IRelationalTypeMappingSource, SqliteTypeMappingSource>()
.AddSingleton<LoggingDefinitions, SqliteLoggingDefinitions>();
}
}
8 changes: 0 additions & 8 deletions src/EFCore.Sqlite.Core/Properties/AssemblyInfo.cs

This file was deleted.

68 changes: 68 additions & 0 deletions test/EFCore.Relational.Specification.Tests/DesignTimeTestBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Reflection;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Migrations.Design;
using Microsoft.EntityFrameworkCore.Scaffolding;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

namespace Microsoft.EntityFrameworkCore
{
public abstract class DesignTimeTestBase<TFixture> : IClassFixture<TFixture>
where TFixture : DesignTimeTestBase<TFixture>.DesignTimeFixtureBase
{
protected TFixture Fixture { get; }

protected DesignTimeTestBase(TFixture fixture)
=> Fixture = fixture;

protected abstract Assembly ProviderAssembly { get; }

[ConditionalFact]
public void Can_get_reverse_engineering_services()
{
using var context = Fixture.CreateContext();
var serviceCollection = new ServiceCollection()
.AddEntityFrameworkDesignTimeServices();
((IDesignTimeServices)Activator.CreateInstance(
ProviderAssembly.GetType(
ProviderAssembly.GetCustomAttribute<DesignTimeProviderServicesAttribute>().TypeName,
throwOnError: true))!)
.ConfigureDesignTimeServices(serviceCollection);
using var services = serviceCollection.BuildServiceProvider();

var reverseEngineerScaffolder = services.GetService<IReverseEngineerScaffolder>();

Assert.NotNull(reverseEngineerScaffolder);
}

[ConditionalFact]
public void Can_get_migrations_services()
{
using var context = Fixture.CreateContext();
var serviceCollection = new ServiceCollection()
.AddEntityFrameworkDesignTimeServices()
.AddDbContextDesignTimeServices(context);
((IDesignTimeServices)Activator.CreateInstance(
ProviderAssembly.GetType(
ProviderAssembly.GetCustomAttribute<DesignTimeProviderServicesAttribute>().TypeName,
throwOnError: true))!)
.ConfigureDesignTimeServices(serviceCollection);
using var services = serviceCollection.BuildServiceProvider();

var migrationsScaffolder = services.GetService<IMigrationsScaffolder>();

Assert.NotNull(migrationsScaffolder);
}

public abstract class DesignTimeFixtureBase : SharedStoreFixtureBase<PoolableDbContext>
{
protected override string StoreName
=> "DesignTimeTest";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EFCore.Design\EFCore.Design.csproj" />
<ProjectReference Include="..\..\src\EFCore.Relational\EFCore.Relational.csproj" />
<ProjectReference Include="..\EFCore.Specification.Tests\EFCore.Specification.Tests.csproj" />
</ItemGroup>
Expand Down
26 changes: 26 additions & 0 deletions test/EFCore.SqlServer.FunctionalTests/DesignTimeSqlServerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Reflection;
using Microsoft.EntityFrameworkCore.SqlServer.Design.Internal;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore
{
public class DesignTimeSqlServerTest : DesignTimeTestBase<DesignTimeSqlServerTest.DesignTimeSqlServerFixture>
{
public DesignTimeSqlServerTest(DesignTimeSqlServerFixture fixture)
: base(fixture)
{
}

protected override Assembly ProviderAssembly
=> typeof(SqlServerDesignTimeServices).Assembly;

public class DesignTimeSqlServerFixture : DesignTimeFixtureBase
{
protected override ITestStoreFactory TestStoreFactory
=> SqlServerTestStoreFactory.Instance;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\EFCore.Design\EFCore.Design.csproj" />
<ProjectReference Include="..\..\src\EFCore.SqlServer.NTS\EFCore.SqlServer.NTS.csproj" />
<ProjectReference Include="..\EFCore.Relational.Specification.Tests\EFCore.Relational.Specification.Tests.csproj" />
</ItemGroup>
Expand Down
26 changes: 26 additions & 0 deletions test/EFCore.Sqlite.FunctionalTests/DesignTimeSqliteTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Reflection;
using Microsoft.EntityFrameworkCore.Sqlite.Design.Internal;
using Microsoft.EntityFrameworkCore.TestUtilities;

namespace Microsoft.EntityFrameworkCore
{
public class DesignTimeSqliteTest : DesignTimeTestBase<DesignTimeSqliteTest.DesignTimeSqliteFixture>
{
public DesignTimeSqliteTest(DesignTimeSqliteFixture fixture)
: base(fixture)
{
}

protected override Assembly ProviderAssembly
=> typeof(SqliteDesignTimeServices).Assembly;

public class DesignTimeSqliteFixture : DesignTimeFixtureBase
{
protected override ITestStoreFactory TestStoreFactory
=> SqliteTestStoreFactory.Instance;
}
}
}