/// <summary>
        ///     <para>
        ///         Creates the service dependencies parameter object for a <see cref="HistoryRepository" />.
        ///     </para>
        ///     <para>
        ///         Do not call this constructor directly from either provider or application code as it may change
        ///         as new dependencies are added. Instead, use this type in your constructor so that an instance
        ///         will be created and injected automatically by the dependency injection container. To create
        ///         an instance with some dependent services replaced, first resolve the object from the dependency
        ///         injection container, then replace selected services using the 'With...' methods. Do not call
        ///         the constructor at any point in this process.
        ///     </para>
        ///     <para>
        ///         This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///         directly from your code. This API may change or be removed in future releases.
        ///     </para>
        /// </summary>
        /// <param name="databaseCreator"> The database creator. </param>
        /// <param name="rawSqlCommandBuilder"> A command builder for building raw SQL commands. </param>
        /// <param name="connection"> The connection to the database. </param>
        /// <param name="options"> Options for the current context instance. </param>
        /// <param name="modelDiffer"> The model differ. </param>
        /// <param name="migrationsSqlGenerator"> The SQL generator for Migrations operations. </param>
        /// <param name="sqlGenerationHelper"> Helpers for generating update SQL. </param>
        /// <param name="coreConventionSetBuilder"> The core convention set to use when creating the model. </param>
        /// <param name="conventionSetBuilders"> The convention sets to use when creating the model. </param>
        public HistoryRepositoryDependencies(
            [NotNull] IRelationalDatabaseCreator databaseCreator,
            [NotNull] IRawSqlCommandBuilder rawSqlCommandBuilder,
            [NotNull] IRelationalConnection connection,
            [NotNull] IDbContextOptions options,
            [NotNull] IMigrationsModelDiffer modelDiffer,
            [NotNull] IMigrationsSqlGenerator migrationsSqlGenerator,
            [NotNull] ISqlGenerationHelper sqlGenerationHelper,
            [NotNull] ICoreConventionSetBuilder coreConventionSetBuilder,
            [NotNull] IEnumerable <IConventionSetBuilder> conventionSetBuilders)
        {
            Check.NotNull(databaseCreator, nameof(databaseCreator));
            Check.NotNull(rawSqlCommandBuilder, nameof(rawSqlCommandBuilder));
            Check.NotNull(connection, nameof(connection));
            Check.NotNull(options, nameof(options));
            Check.NotNull(modelDiffer, nameof(modelDiffer));
            Check.NotNull(migrationsSqlGenerator, nameof(migrationsSqlGenerator));
            Check.NotNull(sqlGenerationHelper, nameof(sqlGenerationHelper));
            Check.NotNull(coreConventionSetBuilder, nameof(coreConventionSetBuilder));
            Check.NotNull(conventionSetBuilders, nameof(conventionSetBuilders));

            DatabaseCreator      = databaseCreator;
            RawSqlCommandBuilder = rawSqlCommandBuilder;
            Connection           = connection;
            Options                  = options;
            ModelDiffer              = modelDiffer;
            MigrationsSqlGenerator   = migrationsSqlGenerator;
            SqlGenerationHelper      = sqlGenerationHelper;
            CoreConventionSetBuilder = coreConventionSetBuilder;
            ConventionSetBuilder     = new CompositeConventionSetBuilder((IReadOnlyList <IConventionSetBuilder>)conventionSetBuilders);
        }
예제 #2
0
            protected TestModelBuilder(TestHelpers testHelpers)
            {
                var options = new LoggingOptions();

                options.Initialize(new DbContextOptionsBuilder().EnableSensitiveDataLogging(false).Options);
                ValidationLoggerFactory = new ListLoggerFactory(l => l == DbLoggerCategory.Model.Validation.Name);
                var validationLogger = new DiagnosticsLogger <DbLoggerCategory.Model.Validation>(
                    ValidationLoggerFactory,
                    options,
                    new DiagnosticListener("Fake"));

                ModelLoggerFactory = new ListLoggerFactory(l => l == DbLoggerCategory.Model.Name);
                var modelLogger = new DiagnosticsLogger <DbLoggerCategory.Model>(
                    ModelLoggerFactory,
                    options,
                    new DiagnosticListener("Fake"));

                var contextServices = testHelpers.CreateContextServices();

                var conventionSet = new CompositeConventionSetBuilder(
                    contextServices.GetRequiredService <IEnumerable <IConventionSetBuilder> >().ToList())
                                    .AddConventions(
                    new CoreConventionSetBuilder(
                        contextServices.GetRequiredService <CoreConventionSetBuilderDependencies>().With(modelLogger))
                    .CreateConventionSet());

                conventionSet.ModelBuiltConventions.Add(
                    new ValidatingConvention(
                        new ModelValidator(new ModelValidatorDependencies(validationLogger, modelLogger))));

                ModelBuilder = new ModelBuilder(conventionSet);
            }
        public ModelBuilder CreateConventionBuilder(IServiceProvider contextServices)
        {
            var conventionSetBuilder = new CompositeConventionSetBuilder(
                contextServices.GetRequiredService <IEnumerable <IConventionSetBuilder> >().ToList());
            var conventionSet = contextServices.GetRequiredService <ICoreConventionSetBuilder>().CreateConventionSet();

            conventionSet = conventionSetBuilder.AddConventions(conventionSet);
            return(new ModelBuilder(conventionSet));
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public static ConventionSet CreateConventionSet([NotNull] DbContext context)
        {
            var conventionSet = new CompositeConventionSetBuilder(
                context.GetService <IEnumerable <IConventionSetBuilder> >().ToList())
                                .AddConventions(
                context.GetService <ICoreConventionSetBuilder>().CreateConventionSet());

            conventionSet.ModelBuiltConventions.Add(new ValidatingConvention(context.GetService <IModelValidator>()));

            return(conventionSet);
        }
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public static ConventionSet CreateConventionSet([NotNull] DbContext context)
        {
            var loggers = new DiagnosticsLoggers(
                context.GetService <IDiagnosticsLogger <DbLoggerCategory.Model> >(),
                context.GetService <IDiagnosticsLogger <DbLoggerCategory.Model.Validation> >());

            var conventionSet = new CompositeConventionSetBuilder(
                context.GetService <IEnumerable <IConventionSetBuilder> >().ToList())
                                .AddConventions(context.GetService <ICoreConventionSetBuilder>()
                                                .CreateConventionSet(loggers));

            conventionSet.ModelBuiltConventions.Add(
                new ValidatingConvention(context.GetService <IModelValidator>(), loggers));

            return(conventionSet);
        }
예제 #6
0
        public ModelBuilder CreateConventionBuilder(bool skipValidation = false)
        {
            var contextServices = CreateContextServices();

            var conventionSet = contextServices.GetRequiredService <ICoreConventionSetBuilder>().CreateConventionSet();

            conventionSet = new CompositeConventionSetBuilder(
                contextServices.GetRequiredService <IEnumerable <IConventionSetBuilder> >().ToList())
                            .AddConventions(conventionSet);

            if (!skipValidation)
            {
                conventionSet.ModelBuiltConventions.Add(new ValidatingConvention(contextServices.GetService <IModelValidator>()));
            }

            return(new ModelBuilder(conventionSet));
        }
예제 #7
0
        public ModelBuilder CreateConventionBuilder(
            DiagnosticsLogger <DbLoggerCategory.Model> modelLogger,
            DiagnosticsLogger <DbLoggerCategory.Model.Validation> validationLogger)
        {
            var contextServices = CreateContextServices();

            var conventionSet = new CoreConventionSetBuilder(
                contextServices.GetRequiredService <CoreConventionSetBuilderDependencies>().With(modelLogger))
                                .CreateConventionSet();

            conventionSet = new CompositeConventionSetBuilder(
                contextServices.GetRequiredService <IEnumerable <IConventionSetBuilder> >().ToList())
                            .AddConventions(conventionSet);

            conventionSet.ModelBuiltConventions.Add(new ValidatingConvention(CreateModelValidator(modelLogger, validationLogger)));

            return(new ModelBuilder(conventionSet));
        }
예제 #8
0
        public ModelBuilder CreateConventionBuilder(bool skipValidation = false)
        {
            var contextServices = CreateContextServices();
            var loggers         = new DiagnosticsLoggers(
                contextServices.GetService <IDiagnosticsLogger <DbLoggerCategory.Model.Validation> >(),
                contextServices.GetService <IDiagnosticsLogger <DbLoggerCategory.Model> >());

            var conventionSet = contextServices.GetRequiredService <ICoreConventionSetBuilder>()
                                .CreateConventionSet(loggers);

            conventionSet = new CompositeConventionSetBuilder(
                contextServices.GetRequiredService <IEnumerable <IConventionSetBuilder> >().ToList())
                            .AddConventions(conventionSet);

            if (!skipValidation)
            {
                conventionSet.ModelBuiltConventions.Add(
                    new ValidatingConvention(
                        contextServices.GetService <IModelValidator>(),
                        loggers));
            }

            return(new ModelBuilder(conventionSet));
        }