/// <summary> /// /// </summary> /// <typeparam name="TApi"></typeparam> /// <param name="builder"></param> /// <param name="services"></param> public static RestierApiBuilder AddRestierApi <TApi>(this RestierApiBuilder builder, Action <IServiceCollection> services) where TApi : ApiBase { Ensure.NotNull(builder, nameof(builder)); Ensure.NotNull(services, nameof(services)); builder.Apis.Add(typeof(TApi), (serviceCollection) => { serviceCollection.AddScoped(typeof(TApi), typeof(TApi)) .AddScoped(typeof(ApiBase), typeof(TApi)); serviceCollection.RemoveAll <ODataQuerySettings>() .AddRestierCoreServices() .AddRestierConventionBasedServices(typeof(TApi)); services.Invoke(serviceCollection); serviceCollection.AddChainedService <IModelBuilder, RestierWebApiModelBuilder>(); // The model builder must maintain a singleton life time, for holding states and being injected into // some other services. serviceCollection.AddSingleton(new RestierWebApiModelExtender(typeof(TApi))) .AddChainedService <IModelBuilder, RestierWebApiModelExtender.ModelBuilder>() .AddChainedService <IModelBuilder>((sp, next) => new RestierWebApiOperationModelBuilder(typeof(TApi), next)) .AddChainedService <IModelMapper, RestierWebApiModelExtender.ModelMapper>() .AddChainedService <IQueryExpressionExpander, RestierWebApiModelExtender.QueryExpressionExpander>() .AddChainedService <IQueryExpressionSourcer, RestierWebApiModelExtender.QueryExpressionSourcer>(); serviceCollection.AddRestierDefaultServices(); }); return(builder); }
/// <summary> /// Initializes a new instance of the <see cref="RestierContainerBuilder" /> class. /// </summary> /// <param name="configureApis">Action to configure the <see cref="ApiBase"/> registrations that are available to the Container.</param> /// <remarks> /// The API registrations are re-created every time because new Containers are spun up per-route. It make make more sense to create a static /// instance to do this, so the Dictionary is only created once. /// </remarks> public RestierContainerBuilder(Action <RestierApiBuilder> configureApis = null) { this.configureApis = configureApis; Services = new ServiceCollection(); apiBuilder = new(); routeBuilder = new(); }
/// <summary> /// /// </summary> /// <typeparam name="TApi"></typeparam> /// <param name="builder"></param> /// <returns>The <see cref="RestierApiBuilder"/> instance to allow for fluent method chaining.</returns> public static RestierApiBuilder AddRestierApi <TApi>(this RestierApiBuilder builder) where TApi : ApiBase { return(AddRestierApi <TApi>(builder, services => { })); }