Skip to content

Commit

Permalink
Use primary constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianeicher committed Mar 7, 2024
1 parent b0a27bc commit 0fbdd03
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
7 changes: 2 additions & 5 deletions src/Server/Bindings/ServiceBindingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ namespace OpenServiceBroker.Bindings;
/// Exposes bindings for Service Instances.
/// </summary>
[Route("v2/service_instances/{instance_id}/service_bindings/{binding_id}")]
public class ServiceBindingsController : BrokerControllerBase<IServiceBindingBlocking, IServiceBindingDeferred>
public class ServiceBindingsController(IServiceProvider provider)
: BrokerControllerBase<IServiceBindingBlocking, IServiceBindingDeferred>(provider)
{
public ServiceBindingsController(IServiceProvider provider)
: base(provider)
{}

/// <summary>
/// Fetches a Service Binding.
/// </summary>
Expand Down
15 changes: 4 additions & 11 deletions src/Server/Catalogs/CatalogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ namespace OpenServiceBroker.Catalogs;
/// Exposes a list of all services available on the Service Broker.
/// </summary>
[Route("v2/catalog")]
public class CatalogController : Controller
public class CatalogController(ICatalogService catalogService) : Controller
{
private readonly ICatalogService _catalogService;

public CatalogController(ICatalogService catalogService)
{
_catalogService = catalogService;
}

/// <summary>
/// Gets the catalog of services that the service broker offers.
/// </summary>
Expand All @@ -28,22 +21,22 @@ public async Task<IActionResult> Get()
var requestHeaders = Request.GetTypedHeaders();
var responseHeaders = Response.GetTypedHeaders();

string? eTag = (_catalogService as IETagProvider)?.ETag;
string? eTag = (catalogService as IETagProvider)?.ETag;
if (!string.IsNullOrEmpty(eTag))
{
if (requestHeaders.IfNoneMatch?.Any(x => x.Tag.Value == eTag) ?? false)
return StatusCode((int) HttpStatusCode.NotModified);
responseHeaders.ETag = new(eTag);
}

var lastModified = (_catalogService as ILastModifiedProvider)?.LastModified;
var lastModified = (catalogService as ILastModifiedProvider)?.LastModified;
if (lastModified.HasValue)
{
if (requestHeaders.IfModifiedSince.HasValue && requestHeaders.IfModifiedSince <= lastModified.Value)
return StatusCode((int) HttpStatusCode.NotModified);
responseHeaders.LastModified = lastModified;
}

return Ok(await _catalogService.GetCatalogAsync());
return Ok(await catalogService.GetCatalogAsync());
}
}
7 changes: 2 additions & 5 deletions src/Server/Instances/ServiceInstancesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ namespace OpenServiceBroker.Instances;
/// Exposes Service Instances.
/// </summary>
[Route("v2/service_instances/{instance_id}")]
public class ServiceInstancesController : BrokerControllerBase<IServiceInstanceBlocking, IServiceInstanceDeferred>
public class ServiceInstancesController(IServiceProvider provider)
: BrokerControllerBase<IServiceInstanceBlocking, IServiceInstanceDeferred>(provider)
{
public ServiceInstancesController(IServiceProvider provider)
: base(provider)
{}

/// <summary>
/// Fetches a Service Instance.
/// </summary>
Expand Down

0 comments on commit 0fbdd03

Please sign in to comment.