Inheritance: MonoBehaviour
Exemplo n.º 1
0
        public void CustomProviderFactoryCallsConfigureContainer()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IServiceProviderFactory <MyContainer>, MyContainerFactory>();
            var services = serviceCollection.BuildServiceProvider();

            var startup = StartupLoader.LoadMethods(services, typeof(MyContainerStartup), Environments.Development);

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);

            Assert.IsType <MyContainer>(app.ApplicationServices);
            Assert.True(((MyContainer)app.ApplicationServices).FancyMethodCalled);
        }
Exemplo n.º 2
0
        public void StartupClassCanHandleConfigureServicesThatReturnsNull()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IServiceProviderFactory <IServiceCollection>, DefaultServiceProviderFactory>();
            var services = serviceCollection.BuildServiceProvider();

            var type    = StartupLoader.FindStartupType("Microsoft.AspNetCore.Hosting.Tests", "WithNullConfigureServices");
            var startup = StartupLoader.LoadMethods(services, type, "WithNullConfigureServices");

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection());
            Assert.NotNull(app.ApplicationServices);
            startup.ConfigureDelegate(app);
            Assert.NotNull(app.ApplicationServices);
        }
Exemplo n.º 3
0
        public void ConfigureTest()
        {
            var startup     = new ConfigureTestStartup2();
            var hostBuilder = new HostBuilder().ConfigureServices(s => s.AddSingleton(startup));

            var services = hostBuilder.Build().Services;

            StartupLoader.Configure(services, new EmptyStartup());

            Assert.Throws <InvalidOperationException>(() => StartupLoader.Configure(services, new ConfigureTestStartup0()));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.Configure(services, new ConfigureTestStartup1()));

            StartupLoader.Configure(services, startup);

            Assert.True(startup.Invoked);
        }
Exemplo n.º 4
0
        public void StartupClassMayHaveHostingServicesInjected()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IFakeStartupCallback>(this);
            var services = serviceCollection.BuildServiceProvider();

            var type    = StartupLoader.FindStartupType("Microsoft.AspNetCore.Hosting.Tests", "WithServices");
            var startup = StartupLoader.LoadMethods(services, type, "WithServices");

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);
            startup.ConfigureDelegate(app);

            Assert.Equal(2, _configurationMethodCalledList.Count);
        }
Exemplo n.º 5
0
        public void StartupLoaderCanLoadByType()
        {
            var serviceCollection = new ServiceCollection();
            var services          = serviceCollection.BuildServiceProvider();

            var hostingEnv = new HostingEnvironment();
            var startup    = StartupLoader.LoadMethods(services, typeof(TestStartup), hostingEnv.EnvironmentName);

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);
            startup.ConfigureDelegate(app);

            var foo = app.ApplicationServices.GetRequiredService <SimpleService>();

            Assert.Equal("Configure", foo.Message);
        }
Exemplo n.º 6
0
        public void StartupClassWithConfigureServicesShouldMakeServiceAvailableInConfigure()
        {
            var serviceCollection = new ServiceCollection();
            var services          = serviceCollection.BuildServiceProvider();

            var type    = StartupLoader.FindStartupType("Microsoft.AspNetCore.Hosting.Tests", "WithConfigureServices");
            var startup = StartupLoader.LoadMethods(services, type, "WithConfigureServices");

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);
            startup.ConfigureDelegate(app);

            var foo = app.ApplicationServices.GetRequiredService <StartupWithConfigureServices.IFoo>();

            Assert.True(foo.Invoked);
        }
Exemplo n.º 7
0
        public void StartupLoaderCanLoadByTypeWithEnvironment()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IServiceProviderFactory <IServiceCollection>, DefaultServiceProviderFactory>();
            var services = serviceCollection.BuildServiceProvider();

            var startup = StartupLoader.LoadMethods(services, typeof(TestStartup), "No");

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);

            var ex = Assert.Throws <TargetInvocationException>(() => startup.ConfigureDelegate(app));

            Assert.IsAssignableFrom(typeof(InvalidOperationException), ex.InnerException);
        }
        private void RegisterComponent(IServiceCollection services, IMvcBuilder builder,
                                       Assembly assembly,
                                       List <HisarCacheAttribute> cacheItems)
        {
            var assemblyName = assembly.GetName().Name;
            var componentId  = assembly.GetComponentId();

            ComponentAssemblyLookup.Add(componentId, assembly);

            AssemblyLoadContext.Default.Resolving += DefaultResolving;

            if (cacheItems != null)
            {
                cacheItems.AddRange(assembly.GetTypesAttributes <HisarCacheAttribute>());
            }

            try
            {
                var startupType = StartupLoader.FindStartupType(assemblyName, _env.EnvironmentName);
                if (startupType != null)
                {
                    var startup = StartupTypeLoader.CreateHisarConventionBasedStartup(startupType, ServiceProvider, _env);
                    StartupLookup.Add(componentId, startup);
                    startup.ConfigureServices(services);

                    services.AddMenuBuilders(startupType);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                AssemblyLoadContext.Default.Resolving -= null;
            }

            var manager      = builder.PartManager;
            var assemblyPart = new AssemblyPart(assembly);

            if (!manager.ApplicationParts.Contains(assemblyPart))
            {
                manager.ApplicationParts.Add(assemblyPart);
            }
        }
Exemplo n.º 9
0
        public void StartupWithTwoConfiguresThrows()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddInstance <IFakeStartupCallback>(this);
            var services = serviceCollection.BuildServiceProvider();

            var diagnosticMessages = new List <string>();
            var hostingEnv         = new HostingEnvironment {
                EnvironmentName = "TwoConfigures"
            };
            var loader = new StartupLoader(services, hostingEnv);
            var type   = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages);

            var ex = Assert.Throws <InvalidOperationException>(() => loader.LoadMethods(type, diagnosticMessages));

            Assert.Equal("Having multiple overloads of method 'Configure' is not supported.", ex.Message);
        }
Exemplo n.º 10
0
 public static IServiceHostBuilder UseStartup(this IServiceHostBuilder hostBuilder, Type startupType)
 {
     return(hostBuilder
            .ConfigureServices(services =>
     {
         if (typeof(IStartup).GetTypeInfo().IsAssignableFrom(startupType.GetTypeInfo()))
         {
             services.AddSingleton(typeof(IStartup), startupType);
         }
         else
         {
             services.AddSingleton(typeof(IStartup), sp =>
             {
                 return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType, ""));
             });
         }
     }));
 }
Exemplo n.º 11
0
        public void StartupClassAddsConfigureServicesToApplicationServices(string environment)
        {
            var services = new ServiceCollection().BuildServiceProvider();

            var type    = StartupLoader.FindStartupType("Microsoft.AspNetCore.Hosting.Tests", environment);
            var startup = StartupLoader.LoadMethods(services, type, environment);

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection());
            startup.ConfigureDelegate(app);

            var options = app.ApplicationServices.GetRequiredService <IOptions <FakeOptions> >().Value;

            Assert.NotNull(options);
            Assert.True(options.Configured);
            Assert.Equal(environment, options.Environment);
        }
Exemplo n.º 12
0
        public void StartupWithNoConfigureThrows()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddInstance <IFakeStartupCallback>(this);
            var services = serviceCollection.BuildServiceProvider();

            var diagnosticMessages = new List <string>();
            var hostingEnv         = new HostingEnvironment {
                EnvironmentName = "Boom"
            };
            var loader = new StartupLoader(services, hostingEnv);
            var type   = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages);

            var ex = Assert.Throws <InvalidOperationException>(() => loader.LoadMethods(type, diagnosticMessages));

            Assert.Equal("A method named 'ConfigureBoom' or 'Configure' in the type 'Microsoft.AspNet.Hosting.Fakes.StartupBoom' could not be found.", ex.Message);
        }
Exemplo n.º 13
0
        private void InitServerAndClient()
        {
            Server = new TestServer(WebHost.CreateDefaultBuilder()
                                    .ConfigureServices((context, services) => services.AddSingleton((IConfigurationRoot)context.Configuration))
                                    .ConfigureServices(services =>
            {
                services.AddSingleton <IStartup>(sp =>
                {
                    var startupMethods = StartupLoader.LoadMethods(sp, typeof(TStartup),
                                                                   Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"));
                    return(new TestHostStartupWrapper(this, startupMethods));
                });
            })
                                    // Todo: remove once fixed (see https://github.com/aspnet/Hosting/issues/1137)
                                    .UseSetting(WebHostDefaults.ApplicationKey, typeof(TStartup).Assembly.FullName)
                                    );

            Client = Server.CreateClient();
        }
Exemplo n.º 14
0
        public void ConventionalStartupClass_ConfigureContainerFilters_WrapInRegistrationOrder()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IServiceProviderFactory <MyContainer>, MyContainerFactory>();
            serviceCollection.AddSingleton <IStartupConfigureContainerFilter <MyContainer> >(new TestConfigureContainerFilter(1, overrideAfterService: true));
            serviceCollection.AddSingleton <IStartupConfigureContainerFilter <MyContainer> >(new TestConfigureContainerFilter(2, overrideAfterService: true));
            var services = serviceCollection.BuildServiceProvider();

            var type    = typeof(ConfigureContainerStartupServicesFiltersStartup);
            var startup = StartupLoader.LoadMethods(services, type, "");

            var applicationServices = startup.ConfigureServicesDelegate(serviceCollection);
            var before = applicationServices.GetRequiredService <ServiceBefore>();
            var after  = applicationServices.GetRequiredService <ServiceAfter>();

            Assert.Equal("ConfigureContainerFilter Before 1", before.Message);
            Assert.Equal("ConfigureContainerFilter After 1", after.Message);
        }
Exemplo n.º 15
0
        public void ConventionalStartupClass_StartupServiceFilters_MultipleStartupServiceFiltersRun()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IServiceProviderFactory <IServiceCollection>, DefaultServiceProviderFactory>();
            serviceCollection.AddSingleton <IStartupConfigureServicesFilter>(new TestStartupServicesFilter(1, overrideAfterService: false));
            serviceCollection.AddSingleton <IStartupConfigureServicesFilter>(new TestStartupServicesFilter(2, overrideAfterService: true));
            var services = serviceCollection.BuildServiceProvider();

            var type    = typeof(VoidReturningStartupServicesFiltersStartup);
            var startup = StartupLoader.LoadMethods(services, type, "");

            var applicationServices = startup.ConfigureServicesDelegate(serviceCollection);
            var before = applicationServices.GetRequiredService <ServiceBefore>();
            var after  = applicationServices.GetRequiredService <ServiceAfter>();

            Assert.Equal("StartupServicesFilter Before 1", before.Message);
            Assert.Equal("StartupServicesFilter After 2", after.Message);
        }
Exemplo n.º 16
0
        public void ConventionalStartupClass_StartupServicesFilters_ThrowsIfStartupBuildsTheContainerAsync()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IServiceProviderFactory <IServiceCollection>, DefaultServiceProviderFactory>();
            serviceCollection.AddSingleton <IStartupConfigureServicesFilter>(new TestStartupServicesFilter(1, overrideAfterService: false));
            var services = serviceCollection.BuildServiceProvider();

            var type    = typeof(IServiceProviderReturningStartupServicesFiltersStartup);
            var startup = StartupLoader.LoadMethods(services, type, "");

            var expectedMessage = $"A ConfigureServices method that returns an {nameof(IServiceProvider)} is " +
                                  $"not compatible with the use of one or more {nameof(IStartupConfigureServicesFilter)}. " +
                                  $"Use a void returning ConfigureServices method instead or a ConfigureContainer method.";

            var exception = Assert.Throws <InvalidOperationException>(() => startup.ConfigureServicesDelegate(serviceCollection));

            Assert.Equal(expectedMessage, exception.Message);
        }
Exemplo n.º 17
0
 public static IGrpcHostBuilder UseStartup(this IGrpcHostBuilder builder, Type startupType)
 {
     return(builder.ConfigureServices(services =>
     {
         if (typeof(IStartup).GetTypeInfo().IsAssignableFrom(startupType.GetTypeInfo()))
         {
             services.AddSingleton(typeof(IStartup), startupType);
         }
         else
         {
             services.AddSingleton(typeof(IStartup), sp =>
             {
                 var hostingEnvironment = sp.GetRequiredService <IHostingEnvironment>();
                 return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType,
                                                                             hostingEnvironment.EnvironmentName));
             });
         }
     }));
 }
Exemplo n.º 18
0
        public void StartupClassAddsConfigureServicesToApplicationServicesCaseInsensitive(string environment)
        {
            var services = new ServiceCollection()
                           .AddSingleton <IServiceProviderFactory <IServiceCollection>, DefaultServiceProviderFactory>()
                           .BuildServiceProvider();
            var type    = StartupLoader.FindStartupType("Microsoft.AspNetCore.Hosting.Tests", environment);
            var startup = StartupLoader.LoadMethods(services, type, environment);

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection());
            startup.ConfigureDelegate(app); // By this not throwing, it found "ConfigureCaseInsensitive"

            var options = app.ApplicationServices.GetRequiredService <IOptions <FakeOptions> >().Value;

            Assert.NotNull(options);
            Assert.True(options.Configured);
            Assert.Equal("ConfigureCaseInsensitiveServices", options.Environment);
        }
Exemplo n.º 19
0
        public static IWorkerHostBuilder UseStartup(this IWorkerHostBuilder hostBuilder, Type startupType)
        {
            var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name;

            if (typeof(IStartup).GetTypeInfo().IsAssignableFrom(startupType.GetTypeInfo()))
            {
                hostBuilder.Services.AddSingleton(typeof(IStartup), startupType);
            }
            else
            {
                hostBuilder.Services.AddSingleton(typeof(IStartup), sp =>
                {
                    var hostingEnvironment = sp.GetRequiredService <IWorkerHostingEnvironment>();
                    return(new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType, hostingEnvironment.EnvironmentName)));
                });
            }

            return(hostBuilder);
        }
Exemplo n.º 20
0
        public void StartupLoaderCanLoadByTypeWithEnvironment()
        {
            var serviceCollection = new ServiceCollection();
            var services          = serviceCollection.BuildServiceProvider();

            var diagnosticMessages = new List <string>();
            var hostingEnv         = new HostingEnvironment {
                EnvironmentName = "No"
            };
            var loader  = new StartupLoader(services, hostingEnv);
            var startup = loader.LoadMethods(typeof(TestStartup), diagnosticMessages);

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);

            var ex = Assert.Throws <TargetInvocationException>(() => startup.ConfigureDelegate(app));

            Assert.IsAssignableFrom(typeof(InvalidOperationException), ex.InnerException);
        }
        public DelegatedStatelessWebServiceStartup(
            IServiceProvider provider,
            IHostEnvironment env,
            Action<IServiceCollection> configureServices)
        {
            _configureServices = configureServices;
            if (typeof(IStartup).IsAssignableFrom(typeof(TStartup)))
            {
                _startupImplementation = (IStartup) ActivatorUtilities.CreateInstance<TStartup>(provider)!;
            }
            else
            {
#if !NETCOREAPP3_1
                var methods = StartupLoader.LoadMethods(provider, typeof(TStartup), env.EnvironmentName);
                _startupImplementation = new ConventionBasedStartup(methods);
#else
                throw new InvalidOperationException($"Type '{typeof(TStartup).FullName}' must implement {typeof(IStartup).FullName}");
#endif
            }
        }
Exemplo n.º 22
0
        public void StartupClassCanHandleConfigureServicesThatReturnsNull()
        {
            var serviceCollection = new ServiceCollection();
            var services          = serviceCollection.BuildServiceProvider();

            var diagnosticMessages = new List <string>();
            var hostingEnv         = new HostingEnvironment {
                EnvironmentName = "WithNullConfigureServices"
            };
            var loader  = new StartupLoader(services, hostingEnv);
            var type    = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages);
            var startup = loader.LoadMethods(type, diagnosticMessages);

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(new ServiceCollection());
            Assert.NotNull(app.ApplicationServices);
            startup.ConfigureDelegate(app);
            Assert.NotNull(app.ApplicationServices);
        }
Exemplo n.º 23
0
 public InternalVirtualHost(
     PathString appBase,
     List <IHostModule> modules)
 {
     _appBase    = appBase;
     Pages       = new ReadOnlyCollection <Page>(modules.SelectMany(x => x.Pages).ToList());
     _testServer = new TestServer(new WebHostBuilder()
                                  .UseSetting(WebHostDefaults.ApplicationKey, Assembly.GetEntryAssembly().GetName().Name)
                                  .ConfigureLogging(factory => {
         factory.AddConsole();
     })
                                  .ConfigureServices(services => {
         services.AddSingleton <Startup>();
         services.AddSingleton(modules);
         services.AddSingleton(typeof(IStartup), sp =>
         {
             var hostingEnvironment = sp.GetRequiredService <IHostingEnvironment>();
             return(new ConventionBasedStartup(StartupLoader.LoadMethods(sp, typeof(Startup), hostingEnvironment.EnvironmentName)));
         });
     }));
 }
Exemplo n.º 24
0
        /// <summary>
        /// Configures the host services with a Startup class
        /// </summary>
        /// <typeparam name ="TStartup">The type used to configure services</typeparam>
        /// <param name="hostBuilder">The <see cref="IXamarinHostBuilder"/> to configure.</param>
        /// <param name="startup">The instance of startup class to configure services with</param>
        /// <returns>The <see cref="IXamarinHostBuilder"/>.</returns>
        public static IXamarinHostBuilder UseStartup <TStartup>(this IXamarinHostBuilder hostBuilder, TStartup startup) where TStartup : class
        {
            var startupType = typeof(TStartup);

            return(hostBuilder
                   .ConfigureServices((context, services) =>
            {
                if (typeof(IXamarinStartup).GetTypeInfo().IsAssignableFrom(startupType.GetTypeInfo()))
                {
                    services.AddSingleton((IXamarinStartup)startup);
                }
                else
                {
                    services.AddSingleton <IXamarinStartup>(sp =>
                    {
                        var hostingEnvironment = sp.GetRequiredService <IXamarinHostEnvironment>();
                        return new XamarinStartup(StartupLoader.LoadMethods(startup, hostingEnvironment.EnvironmentName));
                    });
                }
            }));
        }
Exemplo n.º 25
0
        public void ConventionalStartupClass_StartupServiceFilters_WrapsConfigureServicesMethod()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IServiceProviderFactory <IServiceCollection>, DefaultServiceProviderFactory>();
#pragma warning disable CS0612 // Type or member is obsolete
            serviceCollection.AddSingleton <IStartupConfigureServicesFilter>(new TestStartupServicesFilter(1, overrideAfterService: true));
            serviceCollection.AddSingleton <IStartupConfigureServicesFilter>(new TestStartupServicesFilter(2, overrideAfterService: true));
#pragma warning restore CS0612 // Type or member is obsolete
            var services = serviceCollection.BuildServiceProvider();

            var type    = typeof(VoidReturningStartupServicesFiltersStartup);
            var startup = StartupLoader.LoadMethods(services, type, "");

            var applicationServices = startup.ConfigureServicesDelegate(serviceCollection);
            var before = applicationServices.GetRequiredService <ServiceBefore>();
            var after  = applicationServices.GetRequiredService <ServiceAfter>();

            Assert.Equal("StartupServicesFilter Before 1", before.Message);
            Assert.Equal("StartupServicesFilter After 1", after.Message);
        }
Exemplo n.º 26
0
        public void CreateHostBuilderTest()
        {
            Assert.Null(StartupLoader.CreateHostBuilder(new EmptyStartup(), Name));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.CreateHostBuilder(new CreateHostBuilderTestStartup0(), new AssemblyName()));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.CreateHostBuilder(new CreateHostBuilderTestStartup0(), Name));

            object startup = new CreateHostBuilderTestStartup1();

            Assert.Equal(startup, StartupLoader.CreateHostBuilder(startup, Name)?.Build().Services.GetService <CreateHostBuilderTestStartup1>());

            startup = new CreateHostBuilderTestStartup2();
            Assert.Equal(startup, StartupLoader.CreateHostBuilder(startup, Name)?.Build().Services.GetService <CreateHostBuilderTestStartup2>());

            Assert.Throws <InvalidOperationException>(() => StartupLoader.CreateHostBuilder(new CreateHostBuilderTestStartup3(), Name));

            Assert.Equal(Name, StartupLoader.CreateHostBuilder(new CreateHostBuilderTestStartup4(), Name)?.Build().Services.GetService <AssemblyName>());

            Assert.Throws <InvalidOperationException>(() => StartupLoader.CreateHostBuilder(new CreateHostBuilderTestStartup5(), Name));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Specify the startup type to be used by the web host.
        /// </summary>
        /// <param name="hostBuilder">The <see cref="OicHostBuilder"/> to configure.</param>
        /// <param name="startupType">The <see cref="Type"/> to be used.</param>
        /// <returns>The <see cref="OicHostBuilder"/>.</returns>
        public static OicHostBuilder UseStartup(this OicHostBuilder hostBuilder, Type startupType)
        {
            var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name;

            return(hostBuilder
                   .UseSetting(OicHostDefaults.ApplicationKey, startupAssemblyName)
                   .ConfigureServices(services =>
            {
                if (typeof(IStartup).GetTypeInfo().IsAssignableFrom(startupType.GetTypeInfo()))
                {
                    services.AddSingleton(typeof(IStartup), startupType);
                }
                else
                {
                    services.AddSingleton(typeof(IStartup), sp =>
                    {
                        var hostingEnvironment = sp.GetRequiredService <IHostingEnvironment>();
                        return new ConventionBasedStartup(StartupLoader.LoadMethods(sp, startupType, hostingEnvironment.EnvironmentName));
                    });
                }
            }));
        }
Exemplo n.º 28
0
        public void ConfigureHostTest()
        {
            var hostBuilder = new HostBuilder();

            StartupLoader.ConfigureHost(hostBuilder, new EmptyStartup());

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureHost(hostBuilder, new ConfigureHostTestStartup0()));

            StartupLoader.ConfigureHost(hostBuilder, new ConfigureHostTestStartup1());

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureHost(hostBuilder, new ConfigureHostTestStartup2()));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureHost(hostBuilder, new ConfigureHostTestStartup3()));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureHost(hostBuilder, new ConfigureHostTestStartup4()));

            Assert.Throws <InvalidOperationException>(() => StartupLoader.ConfigureHost(hostBuilder, new ConfigureHostTestStartup7()));

            var services = hostBuilder.Build().Services;

            Assert.NotNull(services.GetService <ConfigureHostTestStartup1>());
        }
Exemplo n.º 29
0
        public void StartupClassMayHaveHostingServicesInjected()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddInstance <IFakeStartupCallback>(this);
            var services = serviceCollection.BuildServiceProvider();

            var diagnosticMessages = new List <string>();
            var hostingEnv         = new HostingEnvironment {
                EnvironmentName = "WithServices"
            };
            var loader  = new StartupLoader(services, hostingEnv);
            var type    = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages);
            var startup = loader.LoadMethods(type, diagnosticMessages);

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);
            startup.ConfigureDelegate(app);

            Assert.Equal(2, _configurationMethodCalledList.Count);
        }
Exemplo n.º 30
0
        public void StartupClassWithConfigureServicesShouldMakeServiceAvailableInConfigure()
        {
            var serviceCollection = new ServiceCollection();
            var services          = serviceCollection.BuildServiceProvider();

            var diagnosticMessages = new List <string>();
            var hostingEnv         = new HostingEnvironment {
                EnvironmentName = "WithConfigureServices"
            };
            var loader  = new StartupLoader(services, hostingEnv);
            var type    = loader.FindStartupType("Microsoft.AspNet.Hosting.Tests", diagnosticMessages);
            var startup = loader.LoadMethods(type, diagnosticMessages);

            var app = new ApplicationBuilder(services);

            app.ApplicationServices = startup.ConfigureServicesDelegate(serviceCollection);
            startup.ConfigureDelegate(app);

            var foo = app.ApplicationServices.GetRequiredService <StartupWithConfigureServices.IFoo>();

            Assert.True(foo.Invoked);
        }
        /// <summary>
        /// These are performed inside a thread to stop the view loading from being blocked. 
        /// </summary>
        private void ThreadEntry()
        {
            using (NSAutoreleasePool pool = new NSAutoreleasePool())
            {
                StartupLoader loader = new StartupLoader();
                loader.InitializeDatabase();
                loader.ClearOldItems();
                loader.LoadSettings();
                loader.LoadMonoTouchDialog();
                loader.LoadCategories();
                loader.LoadItems();
                loader.LoadSites();
                loader.LoadHtmlTemplates();

                // Fade out container view
                InvokeOnMainThread(delegate
                {
                    // Add the UINav controller, send it to the back so it's hidden
                    _rootController = new RootController();
                    _rootController.View.Frame = new RectangleF(0,-20,320,480);
                    View.AddSubview(_rootController.View);
                    View.SendSubviewToBack(_rootController.View);

                    UIView.BeginAnimations(null);
                    UIView.SetAnimationDuration(0.5);
                    UIView.SetAnimationTransition(UIViewAnimationTransition.None,_containerView,true);
                    UIView.SetAnimationDelegate(this);
                        UIView.SetAnimationDidStopSelector(new Selector("fadeOutDidFinish"));
                    _containerView.Alpha = 0;
                    UIView.CommitAnimations();
                });
            }
        }