Starting with version 2.0.0 the ServiceComposer.AspNetCore
package targets only the following frameworks
ServiceComposer uses ASP.Net endpoints. The RunCompositionGateway
API is deprecated in favor of explict ASP.Net endpoint configuration; Use the new endpoints mapping API:
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.UseRouting();
app.UseEndpoints(builder => builder.MapCompositionHandlers());
}
Extending the IRouteBuilder
intrerface to map custom route is not anymore supported. Instead, use mapping attributes on composition handlers. See below for details about the composition handlers API.
Version 2.0.0
introduces a new composition API. IHandleRequests
, IPublishCompositionEvents
, and IHandleRequestsErrors
are not supported anymore.
The IHandleRequests
has been replaced by ICompositionRequestsHandler
:
public class SampleHandler : ICompositionRequestsHandler
{
[HttpGet("/sample/{id}")]
public Task Handle(HttpRequest request)
{
return Task.CompletedTask;
}
}
NOTE: The IInterceptRoutes.Matches
method has been replaced by routing attributes, HttpGet
, HttpPost
, etc.
The ISubscribeToCompositionEvents
has been replaced by the new ICompositionEventsSubscriber
:
public class SamplePublisher : ICompositionEventsSubscriber
{
[HttpGet("/sample/{id}")]
public void Subscribe(ICompositionEventsPublisher publisher)
{
// Use the publisher to subscriber to published events
publisher.Subscribe<SampleEvent>((evt, httpRequest)=>
{
// Handle the event
return Task.CompletedTask;
});
}
}
NOTE: The IInterceptRoutes.Matches
method has been replaced by routing attributes, HttpGet
, HttpPost
, etc.
The IHandleRequestsErrors
has been replaced by ICompositionErrorsHandler
:
public class SampleErrorHandler : ICompositionErrorsHandler
{
public Task OnRequestError(HttpRequest request, Exception ex)
{
return Task.CompletedTask;
}
}
DynamicViewModel
doesn’t implement ICompositionContext
anymore. The composition context can be retrived from the current HttpRequest
:
var context = request.GetCompositionContext();
To raise an event use the composition context API:
await context.RaiseEvent(new AnEvent());
The composition context also exposes the current request identifier:
var requestId = context.RequestId;
By default ServiceComposer responds only to HTTP GET
requests, to enable write support, for example to handle POST
requests, the following configuration can be used when adding ServiceComposer to the application:
public void ConfigureServices(IServiceCollection services)
{
services.AddViewModelComposition(options => options.EnableWriteSupport());
}
When using composition over controllers route matching is now case insensitive by default. The previous behavior can be configured via the composition over controllers options:
public void ConfigureServices(IServiceCollection services)
{
services.AddViewModelComposition(config =>
{
config.EnableCompositionOverControllers(useCaseInsensitiveRouteMatching: false);
});
}