Closed Layla-P closed 2 years ago
Current implementation of Streams requires user to add the stream-related service to the StreamHost Builder, like so:
await StreamHost.CreateDefaultBuilder<ProducerVotingService>(args) .ConfigureWebHostDefaults(webhostBuilder => webhostBuilder.UseStartup<Startup>()) .RunConsoleAsync();
under the hood this implementation of the generic host builder does the following:
_hostBuilder = hostBuilder.AddSpringBootConfiguration() .ConfigureServices((context, services) => services.AddStreamServices<T>(context.Configuration));
public static IHostBuilder AddStreamServices<T>(this IHostBuilder builder) { return builder.AddSpringBootConfiguration() .ConfigureServices((context, services) => { services.AddStreamServices<T>(context.Configuration); services.AddHostedService<StreamLifeCycleService>(); }); }
IMO, this obfuscates what is actually happening and deviates from how other services are added with Steeltoe.
I think it would be better to primarily document adding Streams like so:
await Host.CreateDefaultBuilder(args) .AddStreamServices<ProducerVotingService>() .ConfigureWebHostDefaults(webhostBuilder => webhostBuilder.UseStartup<Startup>()) .RunConsoleAsync();
Which more easily supports the minimal hosting model like this:
using Microsoft.AspNetCore.Mvc; using Steeltoe.Stream.Extensions; using VoteProducer; var builder = WebApplication.CreateBuilder(args); // Add services to the container. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.AddStreamServices<ProducerVotingService>(); builder.Services.AddSingleton<ProducerVotingService>(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.MapGet("/weatherforecast", (ProducerVotingService vs, string choice) => { var response = vs .Record(new Vote { Choice = choice ?? "default" }); return response? 200 : 500; }); app.Run();
Then as an alternative implementation for a service that is solely meant to stream, offer the StreamHost implementation
StreamHost
Closing - opened in wrong repo
Current implementation of Streams requires user to add the stream-related service to the StreamHost Builder, like so:
under the hood this implementation of the generic host builder does the following:
IMO, this obfuscates what is actually happening and deviates from how other services are added with Steeltoe.
I think it would be better to primarily document adding Streams like so:
Which more easily supports the minimal hosting model like this:
Then as an alternative implementation for a service that is solely meant to stream, offer the
StreamHost
implementation