Skip to content

Upgrade to use Endpoints, remove use of Funq, show Swagger/OpenAPI v3… #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions MyApp.Client/Pages/Auth.razor

This file was deleted.

31 changes: 11 additions & 20 deletions MyApp.ServiceInterface/EmailServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,24 @@ public class SmtpConfig
/// <summary>
/// Uses a configured SMTP client to send emails
/// </summary>
public class EmailServices : Service
public class EmailServices(SmtpConfig config, ILogger<EmailServices> log)
// TODO: Uncomment to enable sending emails with SMTP
// : Service
{
public EmailServices(SmtpConfig config, ILogger<EmailServices> log)
{
Config = config;
Log = log;
}

public SmtpConfig Config { get; }
public ILogger<EmailServices> Log { get; }

/* Uncomment to enable sending emails with SMTP
public object Any(SendEmail request)
{
Log.LogInformation("Sending email to {Email} with subject {Subject}", request.To, request.Subject);
log.LogInformation("Sending email to {Email} with subject {Subject}", request.To, request.Subject);

using var client = new SmtpClient(Config.Host, Config.Port);
client.Credentials = new System.Net.NetworkCredential(Config.Username, Config.Password);
using var client = new SmtpClient(config.Host, config.Port);
client.Credentials = new System.Net.NetworkCredential(config.Username, config.Password);
client.EnableSsl = true;

// If DevToEmail is set, send all emails to that address instead
var emailTo = Config.DevToEmail != null
? new MailAddress(Config.DevToEmail)
var emailTo = config.DevToEmail != null
? new MailAddress(config.DevToEmail)
: new MailAddress(request.To, request.ToName);

var emailFrom = new MailAddress(Config.FromEmail, Config.FromName);
var emailFrom = new MailAddress(config.FromEmail, config.FromName);

var msg = new MailMessage(emailFrom, emailTo)
{
Expand All @@ -82,14 +74,13 @@ public object Any(SendEmail request)
IsBodyHtml = request.BodyHtml != null,
};

if (Config.Bcc != null)
if (config.Bcc != null)
{
msg.Bcc.Add(new MailAddress(Config.Bcc));
msg.Bcc.Add(new MailAddress(config.Bcc));
}

client.Send(msg);

return new EmptyResponse();
}
*/
}
4 changes: 1 addition & 3 deletions MyApp.ServiceInterface/TodosServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

namespace MyApp.ServiceInterface;

public class TodosServices : Service
public class TodosServices(IAutoQueryData AutoQuery) : Service
{
public IAutoQueryData AutoQuery { get; set; }

static readonly PocoDataSource<Todo> Todos = PocoDataSource.Create(new Todo[]
{
new () { Id = 1, Text = "Learn" },
Expand Down
2 changes: 1 addition & 1 deletion MyApp.ServiceModel/Hello.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace MyApp.ServiceModel;

[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello : IReturn<HelloResponse>
public class Hello : IGet, IReturn<HelloResponse>
{
public string? Name { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions MyApp/Configure.Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace MyApp;
public class ConfigureAuth : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureAppHost(appHost =>
.ConfigureServices((context, services) =>
{
appHost.Plugins.Add(new AuthFeature(IdentityAuth.For<ApplicationUser>(options => {
services.AddPlugin(new AuthFeature(IdentityAuth.For<ApplicationUser>(options => {
options.EnableCredentialsAuth = true;
options.SessionFactory = () => new CustomUserSession();
})));
Expand Down
13 changes: 5 additions & 8 deletions MyApp/Configure.AutoQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => {
// Enable Audit History
services.AddSingleton<ICrudEvents>(c =>
new OrmLiteCrudEvents(c.Resolve<IDbConnectionFactory>()));
})
.ConfigureAppHost(appHost => {

new OrmLiteCrudEvents(c.GetRequiredService<IDbConnectionFactory>()));
// For TodosService
appHost.Plugins.Add(new AutoQueryDataFeature());

services.AddPlugin(new AutoQueryDataFeature());
// For Bookings https://docs.servicestack.net/autoquery-crud-bookings
appHost.Plugins.Add(new AutoQueryFeature
services.AddPlugin(new AutoQueryFeature
{
MaxLimit = 1000,
//IncludeTotal = true,
});

})
.ConfigureAppHost(appHost => {
appHost.Resolve<ICrudEvents>().InitSchema();
});
}
5 changes: 2 additions & 3 deletions MyApp/Configure.Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public void Configure(IWebHostBuilder builder) => builder
context.Configuration.GetConnectionString("DefaultConnection")
?? ":memory:",
SqliteDialect.Provider));
})
.ConfigureAppHost(appHost => {

// Enable built-in Database Admin UI at /admin-ui/database
appHost.Plugins.Add(new AdminDatabaseFeature());
services.AddPlugin(new AdminDatabaseFeature());
});
}
4 changes: 3 additions & 1 deletion MyApp/Configure.Markdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public void Configure(IWebHostBuilder builder) => builder
services.AddSingleton(AppConfig.Instance);
services.AddSingleton<MarkdownPages>();
services.AddSingleton<MarkdownVideos>();

// Plugins
services.AddPlugin(new CleanUrlsFeature());
})
.ConfigureAppHost(
appHost => appHost.Plugins.Add(new CleanUrlsFeature()),
afterPluginsLoaded: appHost =>
{
var pages = appHost.Resolve<MarkdownPages>();
Expand Down
1 change: 1 addition & 0 deletions MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<ItemGroup>
<PackageReference Include="ServiceStack" Version="8.*" />
<PackageReference Include="ServiceStack.AspNetCore.OpenApi" Version="8.*" />
<PackageReference Include="ServiceStack.Blazor" Version="8.*" />
<PackageReference Include="ServiceStack.Mvc" Version="8.*" />
<PackageReference Include="ServiceStack.OrmLite.Sqlite.Data" Version="8.*" />
Expand Down
19 changes: 18 additions & 1 deletion MyApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using MyApp.Data;
using ServiceStack.Blazor;
using System.Net;
using MyApp.ServiceInterface;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -57,13 +58,26 @@
services.AddBlazorServerIdentityApiClient(baseUrl);
services.AddLocalStorage();

services.AddEndpointsApiExplorer();
services.AddSwaggerGen();

// Register all services
services.AddServiceStack(typeof(MyServices).Assembly, c => {
c.AddSwagger(o => {
//o.AddJwtBearer();
o.AddBasicAuth();
});
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
app.UseMigrationsEndPoint();
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
Expand All @@ -85,7 +99,10 @@
// Add additional endpoints required by the Identity /Account Razor components.
app.MapAdditionalIdentityEndpoints();

app.UseServiceStack(new AppHost());
app.UseServiceStack(new AppHost(), options =>
{
options.MapEndpoints();
});

BlazorConfig.Set(new()
{
Expand Down
7 changes: 7 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="ServiceStack Pre-Release" value="https://f.feedz.io/servicestack/pre-release/nuget/index.json" />
</packageSources>
</configuration>