Skip to content

Commit 1d3898b

Browse files
committed
Update to use aspnet core mapped endpoints.
1 parent 7efb0e5 commit 1d3898b

9 files changed

Lines changed: 36 additions & 30 deletions

MyApp/Configure.AutoQuery.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,14 @@ public void Configure(IWebHostBuilder builder) => builder
1212
// Enable Audit History
1313
services.AddSingleton<ICrudEvents>(c =>
1414
new OrmLiteCrudEvents(c.Resolve<IDbConnectionFactory>()));
15-
})
16-
.ConfigureAppHost(appHost => {
17-
18-
// For TodosService
19-
appHost.Plugins.Add(new AutoQueryDataFeature());
20-
21-
// For Bookings https://docs.servicestack.net/autoquery-crud-bookings
22-
appHost.Plugins.Add(new AutoQueryFeature
15+
services.AddPlugin(new AutoQueryDataFeature());
16+
services.AddPlugin(new AutoQueryFeature
2317
{
2418
MaxLimit = 1000,
2519
//IncludeTotal = true,
2620
});
27-
21+
})
22+
.ConfigureAppHost(appHost => {
2823
appHost.Resolve<ICrudEvents>().InitSchema();
2924
});
3025
}

MyApp/Configure.Db.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ namespace MyApp;
1212
public class ConfigureDb : IHostingStartup
1313
{
1414
public void Configure(IWebHostBuilder builder) => builder
15-
.ConfigureServices((context, services) => {
15+
.ConfigureServices((context, services) =>
16+
{
1617
services.AddSingleton<IDbConnectionFactory>(new OrmLiteConnectionFactory(
1718
context.Configuration.GetConnectionString("DefaultConnection")
1819
?? ":memory:",
1920
SqliteDialect.Provider));
20-
})
21-
.ConfigureAppHost(appHost => {
22-
// Enable built-in Database Admin UI at /admin-ui/database
23-
appHost.Plugins.Add(new AdminDatabaseFeature());
2421
});
2522
}

MyApp/Configure.Markdown.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public void Configure(IWebHostBuilder builder) => builder
1515
services.AddSingleton(AppConfig.Instance);
1616
services.AddSingleton<MarkdownPages>();
1717
services.AddSingleton<MarkdownVideos>();
18+
services.AddPlugin(new CleanUrlsFeature());
1819
})
1920
.ConfigureAppHost(
20-
appHost => appHost.Plugins.Add(new CleanUrlsFeature()),
2121
afterPluginsLoaded: appHost =>
2222
{
2323
var pages = appHost.Resolve<MarkdownPages>();

MyApp/MyApp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
<ItemGroup>
2727
<PackageReference Include="ServiceStack" Version="8.*" />
28+
<PackageReference Include="ServiceStack.AspNetCore.OpenApi" Version="8.0.1" />
2829
<PackageReference Include="ServiceStack.Blazor" Version="8.*" />
2930
<PackageReference Include="ServiceStack.Mvc" Version="8.*" />
3031
<PackageReference Include="ServiceStack.OrmLite.Sqlite.Data" Version="8.*" />

MyApp/Program.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using MyApp.Data;
99
using MyApp.Identity;
1010
using MyApp.Components;
11+
using MyApp.ServiceInterface;
1112

1213
ServiceStack.Licensing.RegisterLicense("OSS MIT 2023 https://github.com/NetCoreApps/BlazorGallery Gj64/BYUNNVLCOjQeagNfHeCC88VX92bVhcM7lwnLj9CRA6hUtBTFL2TYACuEVk+z9WqWIYDDUndA+aJqU1rqoe0OWSEtVuppRH2GzKnDcYcDi3PabbEhyzZ/x8i5J7Z1Gx+JzZLsc6Ctr/svN5hZXPHShcUFL6bhN7nVitwXdU=");
1314

@@ -54,6 +55,17 @@
5455
services.AddBlazorServerIdentityApiClient(baseUrl);
5556
services.AddLocalStorage();
5657

58+
builder.Services.AddEndpointsApiExplorer();
59+
builder.Services.AddSwaggerGen();
60+
61+
// Register all services
62+
builder.Services.AddServiceStack(typeof(MyServices).Assembly, c => {
63+
c.AddSwagger(o => {
64+
//o.AddJwtBearer();
65+
o.AddBasicAuth();
66+
});
67+
});
68+
5769
var app = builder.Build();
5870

5971
// Configure the HTTP request pipeline.
@@ -68,6 +80,9 @@
6880
app.UseHsts();
6981
}
7082

83+
app.UseSwagger();
84+
app.UseSwaggerUI();
85+
7186
app.UseHttpsRedirection();
7287

7388
app.UseStaticFiles();
@@ -79,7 +94,10 @@
7994
// Add additional endpoints required by the Identity /Account Razor components.
8095
app.MapAdditionalIdentityEndpoints();
8196

82-
app.UseServiceStack(new AppHost());
97+
app.UseServiceStack(new AppHost(), options =>
98+
{
99+
options.MapEndpoints();
100+
});
83101

84102
BlazorConfig.Set(new()
85103
{

MyApp/ServiceInterface/EmailServices.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,8 @@ public class SmtpConfig
4848
/// <summary>
4949
/// Uses a configured SMTP client to send emails
5050
/// </summary>
51-
public class EmailServices : Service
51+
public class EmailServices(SmtpConfig Config, ILogger<EmailServices> Log) : Service
5252
{
53-
public EmailServices(SmtpConfig config, ILogger<EmailServices> log)
54-
{
55-
Config = config;
56-
Log = log;
57-
}
58-
59-
public SmtpConfig Config { get; }
60-
public ILogger<EmailServices> Log { get; }
61-
6253
/* Uncomment to enable sending emails with SMTP
6354
public object Any(SendEmail request)
6455
{

MyApp/ServiceInterface/TodosServices.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
namespace MyApp.ServiceInterface;
77

8-
public class TodosServices : Service
8+
public class TodosServices(IAutoQueryData AutoQuery) : Service
99
{
10-
public IAutoQueryData AutoQuery { get; set; }
11-
1210
static readonly PocoDataSource<Todo> Todos = PocoDataSource.Create(new Todo[]
1311
{
1412
new () { Id = 1, Text = "Learn" },

MyApp/appsettings.Development.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
"Default": "Information",
55
"Microsoft.AspNetCore": "Warning"
66
}
7+
},
8+
"SmtpConfig": {
9+
"Host": "localhost"
710
}
811
}

MyApp/appsettings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@
1313
"LocalBaseUrl": "https://localhost:5001",
1414
"PublicBaseUrl": "https://blazor-gallery.servicestack.net"
1515
},
16-
"ApiBaseUrl": "https://blazor-gallery.servicestack.net"
16+
"ApiBaseUrl": "https://blazor-gallery.servicestack.net",
17+
"SmtpConfig": {
18+
"Host": "localhost"
19+
}
1720
}

0 commit comments

Comments
 (0)