/// <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 DesignTimeServicesBuilder(
     [NotNull] AssemblyLoader assemblyLoader,
     [NotNull] StartupInvoker startupInvoker)
 {
     _assemblyLoader = assemblyLoader;
     _startup = startupInvoker;
 }
Exemplo n.º 2
0
 /// <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 DesignTimeServicesBuilder(
     [NotNull] AssemblyLoader assemblyLoader,
     [NotNull] StartupInvoker startupInvoker)
 {
     _assemblyLoader = assemblyLoader;
     _startup        = startupInvoker;
 }
Exemplo n.º 3
0
        public MigrationsOperations(
            [NotNull] IOperationReporter reporter,
            [NotNull] Assembly assembly,
            [NotNull] Assembly startupAssembly,
            [CanBeNull] string environment,
            [NotNull] string projectDir,
            [NotNull] string contentRootPath,
            [NotNull] string rootNamespace)
        {
            Check.NotNull(reporter, nameof(reporter));
            Check.NotNull(assembly, nameof(assembly));
            Check.NotNull(startupAssembly, nameof(startupAssembly));
            Check.NotNull(projectDir, nameof(projectDir));
            Check.NotEmpty(contentRootPath, nameof(contentRootPath));
            Check.NotNull(rootNamespace, nameof(rootNamespace));

            _reporter          = reporter;
            _assembly          = assembly;
            _projectDir        = projectDir;
            _rootNamespace     = rootNamespace;
            _contextOperations = new DbContextOperations(
                reporter,
                assembly,
                startupAssembly,
                environment,
                contentRootPath);

            var startup = new StartupInvoker(reporter, startupAssembly, environment, contentRootPath);

            _servicesBuilder = new DesignTimeServicesBuilder(startup);
        }
        public void ConfigureDesignTimeServices_is_noop_when_not_found()
        {
            var startup = new StartupInvoker(
                typeof(StartupInvokerTest).GetTypeInfo().Assembly,
                environment: "Unknown");

            startup.ConfigureDesignTimeServices(new ServiceCollection());
        }
        public void ConfigureServices_is_noop_when_not_found()
        {
            var startup = new StartupInvoker(
                typeof(StartupInvokerTest).GetTypeInfo().Assembly,
                environment: "Unknown");

            var services = startup.ConfigureServices();

            Assert.NotNull(services);
        }
        public void ConfigureServices_invokes_method_with_alternative_signature()
        {
            var startup = new StartupInvoker(
                typeof(StartupInvokerTest).GetTypeInfo().Assembly,
                "Alternative");

            var services = startup.ConfigureServices();

            var service = services.GetRequiredService <TestService>();

            Assert.Equal("Alternative", service.Value);
        }
        public void ConfigureServices_invokes_static_methods()
        {
            var startup = new StartupInvoker(
                typeof(StartupInvokerTest).GetTypeInfo().Assembly,
                "Static");

            var services = startup.ConfigureServices();

            var service = services.GetRequiredService <TestService>();

            Assert.Equal("Static", service.Value);
        }
        public void ConfigureServices_uses_Development_environment_when_unspecified()
        {
            var startup = new StartupInvoker(
                typeof(StartupInvokerTest).GetTypeInfo().Assembly,
                environment: null);

            var services = startup.ConfigureServices();

            var service = services.GetRequiredService <TestService>();

            Assert.Equal("Development", service.Value);
        }
        public void ConfigureDesignTimeServices_invokes_static_methods()
        {
            var services = new ServiceCollection();
            var startup  = new StartupInvoker(
                typeof(StartupInvokerTest).GetTypeInfo().Assembly,
                "Static");

            startup.ConfigureDesignTimeServices(services);

            var service = services.BuildServiceProvider().GetRequiredService <TestService>();

            Assert.Equal("Static", service.Value);
        }
        public void ConfigureDesignTimeServices_uses_Development_environment_when_unspecified()
        {
            var services = new ServiceCollection();
            var startup  = new StartupInvoker(
                typeof(StartupInvokerTest).GetTypeInfo().Assembly,
                environment: null);

            startup.ConfigureDesignTimeServices(services);

            var service = services.BuildServiceProvider().GetRequiredService <TestService>();

            Assert.Equal("Development", service.Value);
        }
        public void ConfigureDesignTimeServices_works_on_other_types()
        {
            var services = new ServiceCollection();
            var startup  = new StartupInvoker(
                typeof(StartupInvokerTest).GetTypeInfo().Assembly,
                environment: null);

            startup.ConfigureDesignTimeServices(typeof(NotStartup), services);

            var service = services.BuildServiceProvider().GetRequiredService <TestService>();

            Assert.Equal("NotStartup", service.Value);
        }
        public DbContextOperations(
            [NotNull] IOperationReporter reporter,
            [NotNull] Assembly assembly,
            [NotNull] Assembly startupAssembly)
        {
            Check.NotNull(reporter, nameof(reporter));
            Check.NotNull(assembly, nameof(assembly));
            Check.NotNull(startupAssembly, nameof(startupAssembly));

            _reporter        = reporter;
            _assembly        = assembly;
            _startupAssembly = startupAssembly;

            var startup = new StartupInvoker(reporter, startupAssembly);

            _runtimeServices = startup.ConfigureServices();
        }
Exemplo n.º 13
0
        public DatabaseOperations(
            [NotNull] IOperationReporter reporter,
            [NotNull] Assembly startupAssembly,
            [NotNull] string projectDir,
            [NotNull] string rootNamespace)
        {
            Check.NotNull(reporter, nameof(reporter));
            Check.NotNull(startupAssembly, nameof(startupAssembly));
            Check.NotNull(projectDir, nameof(projectDir));
            Check.NotNull(rootNamespace, nameof(rootNamespace));

            _reporter      = reporter;
            _projectDir    = projectDir;
            _rootNamespace = rootNamespace;

            var startup = new StartupInvoker(reporter, startupAssembly);

            _servicesBuilder = new DesignTimeServicesBuilder(startup);
        }
Exemplo n.º 14
0
        public DbContextOperations([NotNull] ILoggerProvider loggerProvider,
            [NotNull] Assembly assembly,
            [NotNull] Assembly startupAssembly,
            [CanBeNull] string environment,
            [NotNull] string contentRootPath)
        {
            Check.NotNull(loggerProvider, nameof(loggerProvider));
            Check.NotNull(assembly, nameof(assembly));
            Check.NotNull(startupAssembly, nameof(startupAssembly));
            Check.NotEmpty(contentRootPath, nameof(contentRootPath));

            _loggerProvider = loggerProvider;
            _assembly = assembly;
            _startupAssembly = startupAssembly;
            _environment = environment;
            _contentRootPath = contentRootPath;
            _logger = new LazyRef<ILogger>(() => _loggerProvider.CreateCommandsLogger());

            var startup = new StartupInvoker(_logger, startupAssembly, environment, contentRootPath);
            _runtimeServices = startup.ConfigureServices();
        }
Exemplo n.º 15
0
        public DbContextOperations(
            [NotNull] IOperationReporter reporter,
            [NotNull] Assembly assembly,
            [NotNull] Assembly startupAssembly,
            [CanBeNull] string environment,
            [NotNull] string contentRootPath)
        {
            Check.NotNull(reporter, nameof(reporter));
            Check.NotNull(assembly, nameof(assembly));
            Check.NotNull(startupAssembly, nameof(startupAssembly));
            Check.NotEmpty(contentRootPath, nameof(contentRootPath));

            _reporter        = reporter;
            _assembly        = assembly;
            _startupAssembly = startupAssembly;
            _environment     = environment;
            _contentRootPath = contentRootPath;

            var startup = new StartupInvoker(reporter, startupAssembly, environment, contentRootPath);

            _runtimeServices = startup.ConfigureServices();
        }
Exemplo n.º 16
0
        public DatabaseOperations(
            [NotNull] ILoggerProvider loggerProvider,
            [NotNull] AssemblyLoader startupAssemblyLoader,
            [NotNull] Assembly startupAssembly,
            [CanBeNull] string environment,
            [NotNull] string projectDir,
            [NotNull] string contentRootPath,
            [NotNull] string rootNamespace)
        {
            Check.NotNull(startupAssemblyLoader, nameof(startupAssemblyLoader));
            Check.NotNull(loggerProvider, nameof(loggerProvider));
            Check.NotNull(startupAssembly, nameof(startupAssembly));
            Check.NotNull(projectDir, nameof(projectDir));
            Check.NotEmpty(contentRootPath, nameof(contentRootPath));
            Check.NotNull(rootNamespace, nameof(rootNamespace));

            _loggerProvider = loggerProvider;
            _projectDir = projectDir;
            _rootNamespace = rootNamespace;

            var logger = new LazyRef<ILogger>(() => loggerProvider.CreateCommandsLogger());
            var startup = new StartupInvoker(logger, startupAssembly, environment, contentRootPath);
            _servicesBuilder = new DesignTimeServicesBuilder(startupAssemblyLoader, startup);
        }
Exemplo n.º 17
0
 public DesignTimeServicesBuilder(
     [NotNull] StartupInvoker startupInvoker)
 {
     _startup = startupInvoker;
 }
Exemplo n.º 18
0
        public void Invoke_warns_on_error()
        {
            var log = new List<Tuple<LogLevel, string>>();

            var startup = new StartupInvoker(
                new LazyRef<ILogger>(() => new ListLoggerFactory(log).CreateLogger("Test")),
                MockAssembly.Create(typeof(BadStartup)),
                /*environment:*/ null,
                "Irrelevant");

            var services = startup.ConfigureServices();

            Assert.NotNull(services);
            Assert.Equal(
                DesignCoreStrings.InvokeStartupMethodFailed(
                    "ConfigureServices",
                    typeof(BadStartup).DisplayName(),
                    "Something went wrong."),
                log[0].Item2);
        }
Exemplo n.º 19
0
        public void ConfigureServices_injects_services()
        {
            var assembly = MockAssembly.Create(typeof(StartupInjected));
            var startup = new StartupInvoker(
                new LazyRef<ILogger>(() => new LoggerFactory().CreateLogger("Test")),
                assembly,
                "Injected",
                @"C:\The\Right\Path");

            var services = startup.ConfigureServices();
            var service = services.GetRequiredService<TestService>();

            Assert.Equal("Injected", service.Value);
        }