-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3c7efa7
commit b8479de
Showing
7 changed files
with
49 additions
and
103 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
Registerly/samples/Registerly.Samples.WebApi/Controllers/WeatherForecastController.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,63 @@ | ||
using DeviantCoding.Registerly; | ||
using DeviantCoding.Registerly.AttributeRegistration; | ||
using DeviantCoding.Registerly.Strategies.Lifetime; | ||
using Registerly.Samples.WebApi.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
// Start the application and use the provided http file to test it. | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
// Three ways to register the WeatherService class | ||
// Two ways to register service classes: | ||
// - Marking the class with an attribute | ||
// - Manually registering a class | ||
|
||
//builder.RegisterServicesByAttributes(); | ||
builder.RegisterServicesByAttributes(); | ||
|
||
builder.Register(classes => classes | ||
.Where(c => c.Exactly<WeatherService>()) | ||
.FromAssemblyOf<FarewellerService>() | ||
.Where(c => c.Exactly<FarewellerService>()) | ||
.Using<Singleton>()); | ||
|
||
// The following registration is more performant: | ||
//builder.Register(classes => classes | ||
// .FromAssemblyOf<WeatherService>() | ||
// .Where(c => c.Exactly<WeatherService>()) | ||
// .Using<Singleton>()); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
app.MapControllers(); | ||
|
||
app.Run(); | ||
|
||
|
||
|
||
[ApiController] | ||
[Route("chatterbox")] | ||
public class ChatterboxController(IGreeterService greeterService, IFarewellerService farewellerService) : ControllerBase | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
[HttpGet("greet")] | ||
public string Greet() => greeterService.Greet(); | ||
|
||
[HttpGet("farewell")] | ||
public string Farewell() => farewellerService.Farewell(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
public interface IGreeterService | ||
{ | ||
string Greet(); | ||
} | ||
|
||
[Singleton] | ||
public class GreeterService : IGreeterService | ||
{ | ||
public string Greet() => "Hello, World!"; | ||
} | ||
|
||
app.MapControllers(); | ||
public interface IFarewellerService | ||
{ | ||
string Farewell(); | ||
} | ||
|
||
app.Run(); | ||
public class FarewellerService : IFarewellerService | ||
{ | ||
public string Farewell() => "Goodbye, World!"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
Registerly/samples/Registerly.Samples.WebApi/Registerly.Samples.WebApi.http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
@Registerly.Samples.WebApi_HostAddress = http://localhost:5109 | ||
|
||
GET {{Registerly.Samples.WebApi_HostAddress}}/weatherforecast/ | ||
GET {{Registerly.Samples.WebApi_HostAddress}}/chatterbox/greet | ||
Accept: application/json | ||
|
||
### | ||
|
||
GET {{Registerly.Samples.WebApi_HostAddress}}/chatterbox/farewell | ||
Accept: application/json | ||
|
||
### |
28 changes: 0 additions & 28 deletions
28
Registerly/samples/Registerly.Samples.WebApi/Services/WeatherService.cs
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
Registerly/samples/Registerly.Samples.WebApi/WeatherForecast.cs
This file was deleted.
Oops, something went wrong.