internal static RocketWasmHostBuilder GetOrCreateBuilder(IWebAssemblyHostBuilder builder, Assembly assembly = null) { if (!Builders.TryGetValue(builder, out var conventionalBuilder)) { var diagnosticSource = new DiagnosticListener("Rocket.Surgery.Blazor"); var logger = new DiagnosticLogger(diagnosticSource); var serviceProviderDictionary = new ServiceProviderDictionary(builder.Properties); serviceProviderDictionary.Set <ILogger>(logger); serviceProviderDictionary.Set(HostType.Live); var assemblyCandidateFinder = new AppDomainAssemblyCandidateFinder(AppDomain.CurrentDomain, logger); var assemblyProvider = new DefaultAssemblyProvider(AppDomain.CurrentDomain.GetAssemblies().Concat(GetAllAssemblies(assembly !)).ToArray());
/// <summary> /// Gets the or create builder. /// </summary> /// <param name="builder">The builder.</param> /// <returns>RocketHostBuilder.</returns> internal static RocketHostBuilder GetOrCreateBuilder(IHostBuilder builder) { if (!Builders.TryGetValue(builder, out var conventionalBuilder)) { var diagnosticSource = new DiagnosticListener("Rocket.Surgery.Hosting"); var dependencyContext = DependencyContext.Default; var logger = new DiagnosticLogger(diagnosticSource); var serviceProviderDictionary = new ServiceProviderDictionary(builder.Properties); serviceProviderDictionary.Set <ILogger>(logger); var assemblyCandidateFinder = new DependencyContextAssemblyCandidateFinder(dependencyContext, logger); var assemblyProvider = new DependencyContextAssemblyProvider(dependencyContext, logger); var scanner = new SimpleConventionScanner(assemblyCandidateFinder, serviceProviderDictionary, logger); conventionalBuilder = new RocketHostBuilder(builder, scanner, assemblyCandidateFinder, assemblyProvider, diagnosticSource, serviceProviderDictionary); var host = new RocketContext(builder); builder .ConfigureHostConfiguration(host.CaptureArguments) .ConfigureHostConfiguration(host.ConfigureCli) .ConfigureAppConfiguration(host.ReplaceArguments) .ConfigureAppConfiguration(host.ConfigureAppConfiguration) .ConfigureServices(host.ConfigureServices) .ConfigureServices(host.DefaultServices); Builders.Add(builder, conventionalBuilder); } return(conventionalBuilder); }
public void Should_Not_IsUnitTestHost() { var context = A.Fake <IConventionContext>(); var properties = new ServiceProviderDictionary(); A.CallTo(() => context.Properties).Returns(properties); properties.Set(HostType.Live); context.IsUnitTestHost().Should().BeFalse(); }
public void Should_Get_HostType(HostType hostType) { var context = A.Fake <IConventionContext>(); var properties = new ServiceProviderDictionary(); A.CallTo(() => context.Properties).Returns(properties); properties.Set(hostType); context.GetHostType().Should().Be(hostType); }
public void Should_Get_TestHost() { var context = A.Fake <IConventionHostBuilder>(); var properties = new ServiceProviderDictionary(); A.CallTo(() => context.ServiceProperties).Returns(properties); properties.Set(HostType.UnitTestHost); context.IsUnitTestHost().Should().BeTrue(); }
public void MustRegisterListeners_Implicitly() { AutoFake.Provide <IServiceCollection>(new ServiceCollection()); var serviceProviderDictionary = new ServiceProviderDictionary(); AutoFake.Provide <IServiceProviderDictionary>(serviceProviderDictionary); AutoFake.Provide <IServiceProvider>(serviceProviderDictionary); AutoFake.Provide <IDictionary <object, object?> >(serviceProviderDictionary); var scanner = AutoFake.Resolve <SimpleConventionScanner>(); AutoFake.Provide <IConventionScanner>(scanner); serviceProviderDictionary.Set( new MartenOptions { SessionTracking = DocumentTracking.DirtyTracking, UseSession = true } ); var servicesBuilder = AutoFake.Resolve <ServicesBuilder>(); servicesBuilder.Scanner.AppendConvention <MartenConvention>(); servicesBuilder.Services.AddSingleton(A.Fake <IDocumentSessionListener>()); servicesBuilder.Services.AddTransient <MartenRegistry, MyMartenRegistry>(); servicesBuilder.Services.AddSingleton(LoggerFactory); servicesBuilder.Services.AddSingleton <IClock>( new FakeClock( Instant.FromDateTimeOffset(DateTimeOffset.Now), Duration.FromSeconds(1) ) ); servicesBuilder.Services.AddScoped <IMartenContext>( _ => new MartenContext { User = new MartenUser <string>(() => "abc123") } ); var serviceProvider = servicesBuilder.Build(); var options = serviceProvider.GetRequiredService <IOptions <StoreOptions> >().Value; options.Connection(() => new NpgsqlConnection()); var session = serviceProvider.GetService <IDocumentSession>(); session.Listeners.Count.Should().Be(1); }
/// <summary> /// Gets the or create builder. /// </summary> /// <param name="builder">The builder.</param> /// <returns>RocketHostBuilder.</returns> internal static RocketHostBuilder GetOrCreateBuilder(IHostBuilder builder) { if (!Builders.TryGetValue(builder, out var conventionalBuilder)) { var diagnosticSource = new DiagnosticListener("Rocket.Surgery.Hosting"); var dependencyContext = DependencyContext.Default; var logger = new DiagnosticLogger(diagnosticSource); var serviceProviderDictionary = new ServiceProviderDictionary(builder.Properties); serviceProviderDictionary.Set <ILogger>(logger); serviceProviderDictionary.Set(HostType.Live); var assemblyCandidateFinder = new DependencyContextAssemblyCandidateFinder(dependencyContext, logger); var assemblyProvider = new DependencyContextAssemblyProvider(dependencyContext, logger); var scanner = new SimpleConventionScanner(assemblyCandidateFinder, serviceProviderDictionary, logger); conventionalBuilder = new RocketHostBuilder( builder, scanner, assemblyCandidateFinder, assemblyProvider, diagnosticSource, serviceProviderDictionary ); conventionalBuilder.Set( new ConfigurationOptions { ApplicationConfiguration = { b => b.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true), b => b.AddYamlFile("appsettings.yml", optional: true, reloadOnChange: true), b => b.AddYamlFile("appsettings.yaml", optional: true, reloadOnChange: true), b => b.AddIniFile("appsettings.ini", optional: true, reloadOnChange: true) }, EnvironmentConfiguration = { (b, environmentName) => b.AddJsonFile( $"appsettings.{environmentName}.json", optional: true, reloadOnChange: true ), (b, environmentName) => b.AddYamlFile( $"appsettings.{environmentName}.yml", optional: true, reloadOnChange: true ), (b, environmentName) => b.AddYamlFile( $"appsettings.{environmentName}.yaml", optional: true, reloadOnChange: true ), (b, environmentName) => b.AddIniFile( $"appsettings.{environmentName}.ini", optional: true, reloadOnChange: true ) } } ); var host = new RocketContext(builder); builder .ConfigureHostConfiguration(host.ComposeHostingConvention) .ConfigureHostConfiguration(host.CaptureArguments) .ConfigureHostConfiguration(host.ConfigureCli) .ConfigureAppConfiguration(host.ReplaceArguments) .ConfigureAppConfiguration(host.ConfigureAppConfiguration) .ConfigureServices(host.ConfigureServices) .ConfigureServices(host.DefaultServices); Builders.Add(builder, conventionalBuilder); } return(conventionalBuilder); }
/// <summary> /// Gets the or create builder. /// </summary> /// <param name="builder">The builder.</param> /// <param name="startupInstance">The startup instance.</param> /// <param name="environment">The environment.</param> /// <returns>RocketFunctionHostBuilder.</returns> internal static RocketFunctionHostBuilder GetOrCreateBuilder( IWebJobsBuilder builder, object startupInstance, IRocketEnvironment?environment ) { if (!Builders.TryGetValue(builder, out var conventionalBuilder)) { var diagnosticSource = new DiagnosticListener("Rocket.Surgery.Hosting"); var functionsAssembly = startupInstance.GetType().Assembly; var location = Path.GetDirectoryName(functionsAssembly.Location); DependencyContext?dependencyContext = null; while (!string.IsNullOrEmpty(location)) { var depsFilePath = Path.Combine(location, functionsAssembly.GetName().Name + ".deps.json"); if (File.Exists(depsFilePath)) { using var stream = File.Open(depsFilePath, FileMode.Open, FileAccess.Read); using var reader = new DependencyContextJsonReader(); dependencyContext = reader.Read(stream); break; } location = Path.GetDirectoryName(location); } var logger = new DiagnosticLogger(diagnosticSource); var assemblyCandidateFinder = new DependencyContextAssemblyCandidateFinder(dependencyContext !, logger); var assemblyProvider = new DependencyContextAssemblyProvider(dependencyContext !, logger); var properties = new ServiceProviderDictionary(); properties.Set <ILogger>(logger); properties.Set(HostType.Live); var scanner = new SimpleConventionScanner(assemblyCandidateFinder, properties, logger); conventionalBuilder = new RocketFunctionHostBuilder( builder, functionsAssembly, startupInstance, environment !, scanner, assemblyCandidateFinder, assemblyProvider, diagnosticSource, properties ); conventionalBuilder.Set( new ConfigurationOptions { ApplicationConfiguration = { b => b.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true), b => b.AddYamlFile("appsettings.yml", optional: true, reloadOnChange: true), b => b.AddYamlFile("appsettings.yaml", optional: true, reloadOnChange: true), b => b.AddIniFile("appsettings.ini", optional: true, reloadOnChange: true) }, EnvironmentConfiguration = { (b, environmentName) => b.AddJsonFile( $"appsettings.{environmentName}.json", optional: true, reloadOnChange: true ), (b, environmentName) => b.AddYamlFile( $"appsettings.{environmentName}.yml", optional: true, reloadOnChange: true ), (b, environmentName) => b.AddYamlFile( $"appsettings.{environmentName}.yaml", optional: true, reloadOnChange: true ), (b, environmentName) => b.AddIniFile( $"appsettings.{environmentName}.ini", optional: true, reloadOnChange: true ) } } ); Builders.Add(builder, conventionalBuilder); } return(conventionalBuilder); }