/// <summary> /// The default constuctor /// </summary> protected LaunchPadFunctionStartup() { _builder = new ConventionContextBuilder(new Dictionary <object, object?>()) .UseAppDomain(AppDomain.CurrentDomain) .Set(HostType.Live); if (this is IConvention convention) { _builder.AppendConvention(convention); } // TODO: Restore this sometime // var functionsAssembly = this.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, FileShare.Read); // using var reader = new DependencyContextJsonReader(); // dependencyContext = reader.Read(stream); // break; // } // // location = Path.GetDirectoryName(location); // } }
public async Task Test2() { var builder = new ConventionContextBuilder(new Dictionary <object, object?>()); var context = ConventionContext.From(builder .Set <IConfiguration>(new ConfigurationBuilder().Build()) .Set(new MediatRServiceConfiguration().AsSingleton()) .EnableConventionAttributes() .UseAssemblies(new TestAssemblyProvider().GetAssemblies()) ); var services = new ServiceCollection().ApplyConventions(context); var sub = A.Fake <IPipelineBehavior <Request, Unit> >(); services.AddSingleton(sub); services.Should().Contain( x => x.ServiceType == typeof(IMediator) && x.Lifetime == ServiceLifetime.Singleton ); var r = services.BuildServiceProvider(); var mediator = r.GetRequiredService <IMediator>(); await mediator.Send(new Request()).ConfigureAwait(false); A.CallTo(() => sub.Handle(A <Request> ._, A <CancellationToken> ._, A <RequestHandlerDelegate <Unit> > ._)) .MustHaveHappenedOnceExactly(); }
/// <summary> /// The default constructor with the given configuration method /// </summary> /// <param name="configure"></param> protected LaunchPadFunctionStartup(Func <LaunchPadFunctionStartup, ConventionContextBuilder> configure) { _builder = configure(this).Set(HostType.Live); if (this is IConvention convention) { _builder.AppendConvention(convention); } }
/// <summary> /// Uses the autofac. /// </summary> /// <param name="builder">The builder.</param> /// <param name="containerBuilder">The container builder.</param> /// <returns>IWebAssemblyHostBuilder.</returns> public static ConventionContextBuilder UseAutofac(this ConventionContextBuilder builder, ContainerBuilder?containerBuilder = null) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } return(builder.ConfigureHosting((context, builder) => builder.ConfigureContainer(new AutofacConventionServiceProviderFactory(context, containerBuilder)))); }
/// <summary> /// Uses the Autofac. /// </summary> /// <param name="builder">The builder.</param> /// <param name="delegate">The container.</param> /// <returns>IHostBuilder.</returns> public static ConventionContextBuilder ConfigureAutofac(this ConventionContextBuilder builder, Action <ContainerBuilder> @delegate) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.AppendDelegate(new AutofacConvention((context, configuration, services, container) => @delegate(container))); return(builder); }
/// <summary> /// Uses the DryIoc. /// </summary> /// <param name="builder">The builder.</param> /// <param name="delegate">The container.</param> /// <returns>IHostBuilder.</returns> public static ConventionContextBuilder ConfigureDryIoc([NotNull] this ConventionContextBuilder builder, Func <IServiceCollection, IContainer, IContainer> @delegate) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.AppendDelegate(new DryIocConvention((context, configuration, services, container) => @delegate(services, container))); return(builder); }
/// <summary> /// Uses AutoMapper. /// </summary> /// <param name="container">The container.</param> /// <param name="options">The options object</param> /// <returns>IConventionHostBuilder.</returns> public static ConventionContextBuilder UseAutoMapper(this ConventionContextBuilder container, AutoMapperOptions?options = null) { if (container == null) { throw new ArgumentNullException(nameof(container)); } container.PrependConvention <AutoMapperConvention>(); return(container); }
/// <summary> /// Uses the Autofac. /// </summary> /// <param name="builder">The builder.</param> /// <param name="delegate">The container.</param> /// <returns>IHostBuilder.</returns> public static ConventionContextBuilder ConfigureAutofac(this ConventionContextBuilder builder, AutofacConvention @delegate) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.AppendDelegate(@delegate); return(builder); }
protected void Init(Action <ConventionContextBuilder>?action = null) { var conventionContextBuilder = ConventionContextBuilder.Create() .ForTesting(DependencyContext.Load(GetType().Assembly), LoggerFactory) .WithLogger(Logger); action?.Invoke(conventionContextBuilder); var context = ConventionContext.From(conventionContextBuilder); Populate(new ServiceCollection().ApplyConventions(context)); }
/// <summary> /// Fors the assemblies. /// </summary> /// <param name="assemblies">The assemblies.</param> /// <param name="conventionContextBuilderAction"></param> /// <returns>Func<IHostBuilder, ConventionContextBuilder>.</returns> public static Func<LaunchPadFunctionStartup, ConventionContextBuilder> ForAssemblies( IEnumerable<Assembly> assemblies, Action<ConventionContextBuilder>? conventionContextBuilderAction = null ) { return _ => { var conventionContextBuilder = new ConventionContextBuilder(new Dictionary<object, object?>()).UseAssemblies(assemblies); conventionContextBuilderAction?.Invoke(conventionContextBuilder); return conventionContextBuilder; }; }
protected HandleTestHostBase(ITestOutputHelper outputHelper, LogLevel logLevel = LogLevel.Information) : base( outputHelper, logLevel, "[{Timestamp:HH:mm:ss} {Level:w4}] {Message} <{SourceContext}>{NewLine}{Exception}" ) { _context = ConventionContextBuilder.Create() .ForTesting(DependencyContext.Load(GetType().Assembly), LoggerFactory) .WithLogger(LoggerFactory.CreateLogger(nameof(AutoFakeTest))); ExcludeSourceContext(nameof(AutoFakeTest)); }
public Task InitializeAsync() { var conventionContextBuilder = ConventionContextBuilder.Create() .ForTesting(DependencyContext.Load(GetType().Assembly), LoggerFactory) .WithLogger(Logger); var context = ConventionContext.From(conventionContextBuilder); Populate(new ServiceCollection().ApplyConventions(context)); return(Task.CompletedTask); }
/// <summary> /// Fors the application domain. /// </summary> /// <param name="appDomain">The application domain.</param> /// <param name="conventionContextBuilderAction"></param> /// <returns>Func<IHostBuilder, ConventionContextBuilder>.</returns> public static Func<LaunchPadFunctionStartup, ConventionContextBuilder> ForAppDomain( AppDomain appDomain, Action<ConventionContextBuilder>? conventionContextBuilderAction = null ) { return _ => { var conventionContextBuilder = new ConventionContextBuilder(new Dictionary<object, object?>()) .UseAppDomain(appDomain); conventionContextBuilderAction?.Invoke(conventionContextBuilder); return conventionContextBuilder; }; }
/// <summary> /// Configure the serilog delegate to the convention scanner /// </summary> /// <param name="container">The container.</param> /// <param name="delegate">The delegate.</param> /// <returns>IConventionHostBuilder.</returns> public static ConventionContextBuilder ConfigureOpenTelemetryTracing(this ConventionContextBuilder container, OpenTelemetryTracingConvention @delegate) { if (container == null) { throw new ArgumentNullException(nameof(container)); } if (@delegate == null) { throw new ArgumentNullException(nameof(@delegate)); } container.AppendDelegate(@delegate); return(container); }
public NamedSchemaTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { _context = ConventionContext.From( ConventionContextBuilder.Create() .ForTesting(DependencyContext.Load(GetType().Assembly), LoggerFactory) .WithLogger(LoggerFactory.CreateLogger(nameof(AutoFakeTest))) .ConfigureServices( (_, collection) => { collection.AddGraphQL(); collection.AddGraphQL("Named"); } ) ); ExcludeSourceContext(nameof(NamedSchemaTests)); }
protected HandleTestHostBase(ITestOutputHelper outputHelper, LogLevel logLevel = LogLevel.Information) : base( outputHelper, logLevel, "[{Timestamp:HH:mm:ss} {Level:w4}] {Message} <{SourceContext}>{NewLine}{Exception}" ) { _hostBuilder = ConventionContext.From( ConventionContextBuilder.Create() .ForTesting(AppDomain.CurrentDomain, LoggerFactory) .WithLogger(Logger) ); ExcludeSourceContext(nameof(WebAssemblyHostBuilder)); ExcludeSourceContext(nameof(WebAssemblyHost)); ExcludeSourceContext(nameof(DiagnosticSource)); Populate(new ServiceCollection().ApplyConventions(_hostBuilder)); }
/// <summary> /// Configure the serilog delegate to the convention scanner /// </summary> /// <param name="builder">The builder.</param> /// <param name="delegate">The delegate.</param> /// <returns>IHostBuilder.</returns> public static ConventionContextBuilder ConfigureSerilog( [NotNull] this ConventionContextBuilder builder, [NotNull] Action <LoggerConfiguration> @delegate ) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (@delegate == null) { throw new ArgumentNullException(nameof(@delegate)); } return(builder.AppendDelegate(new SerilogConvention((_, _, loggerConfiguration) => @delegate(loggerConfiguration)))); }
/// <summary> /// Configure the serilog delegate to the convention scanner /// </summary> /// <param name="builder">The builder.</param> /// <param name="delegate">The delegate.</param> /// <returns>IHostBuilder.</returns> public static ConventionContextBuilder ConfigureSerilog( [NotNull] this ConventionContextBuilder builder, [NotNull] SerilogConvention @delegate ) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (@delegate == null) { throw new ArgumentNullException(nameof(@delegate)); } return(builder.AppendDelegate(@delegate)); }
public override void Setup(ConventionContextBuilder contextBuilder) { }
/// <summary> /// Method called to setup the conventions /// </summary> /// <param name="contextBuilder"></param> public virtual void Setup(ConventionContextBuilder contextBuilder) { }
/// <summary> /// Use the given rocket booster /// </summary> /// <param name="configure"></param> /// <returns></returns> public LaunchPadFunctionStartup UseRocketBooster(Func <LaunchPadFunctionStartup, ConventionContextBuilder> configure) { _builder = configure(this); return(this); }
/// <summary> /// Use the given rocket booster /// </summary> /// <param name="configure"></param> /// <returns></returns> public LaunchPadFunctionStartup LaunchWith(Func <LaunchPadFunctionStartup, ConventionContextBuilder> configure) { _builder = configure(this); return(this); }