Skip to content

Commit

Permalink
Use services.AddPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Mar 23, 2024
1 parent 0c5e773 commit da15aaf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
7 changes: 3 additions & 4 deletions MyApp/Configure.Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ namespace MyApp;
public class ConfigureAuth : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureAppHost(appHost =>
{
appHost.Plugins.Add(new AuthFeature(IdentityAuth.For<ApplicationUser>(options => {
.ConfigureServices(services => {
services.AddPlugin(new AuthFeature(IdentityAuth.For<ApplicationUser>(options => {
options.SessionFactory = () => new CustomUserSession();
options.CredentialsAuth();
options.AdminUsersFeature();
})));
});
}
}
20 changes: 8 additions & 12 deletions MyApp/Configure.Markdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ namespace MyApp;
public class ConfigureMarkdown : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) =>
{
.ConfigureServices((context, services) => {
context.Configuration.GetSection(nameof(AppConfig)).Bind(AppConfig.Instance);
services.AddSingleton(AppConfig.Instance);
services.AddSingleton<MarkdownPages>();
services.AddSingleton<MarkdownVideos>();
})
.ConfigureAppHost(
appHost => appHost.Plugins.Add(new CleanUrlsFeature()),
afterPluginsLoaded: appHost =>
{
var pages = appHost.Resolve<MarkdownPages>();
var videos = appHost.Resolve<MarkdownVideos>();
.ConfigureAppHost(afterPluginsLoaded: appHost => {
var pages = appHost.Resolve<MarkdownPages>();
var videos = appHost.Resolve<MarkdownVideos>();

pages.LoadFrom("_pages");
videos.LoadFrom("_videos");
AppConfig.Instance.GitPagesBaseUrl ??= ResolveGitBlobBaseUrl(appHost.ContentRootDirectory);
});
pages.LoadFrom("_pages");
videos.LoadFrom("_videos");
AppConfig.Instance.GitPagesBaseUrl ??= ResolveGitBlobBaseUrl(appHost.ContentRootDirectory);
});

private string? ResolveGitBlobBaseUrl(IVirtualDirectory contentDir)
{
Expand Down
13 changes: 7 additions & 6 deletions MyApp/Configure.OpenApi.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
[assembly: HostingStartup(typeof(MyApp.ConfigureOpenApi))]
using MyApp.Data;

[assembly: HostingStartup(typeof(MyApp.ConfigureOpenApi))]

namespace MyApp;

public class ConfigureOpenApi : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) =>
{
.ConfigureServices((context, services) => {
if (context.HostingEnvironment.IsDevelopment())
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();

services.AddServiceStackSwagger();
services.AddBasicAuth<Data.ApplicationUser>();
services.AddBasicAuth<ApplicationUser>();
//services.AddJwtAuth();

services.AddTransient<IStartupFilter, StartupFilter>();
services.AddTransient<IStartupFilter,StartupFilter>();
}
});

Expand Down

0 comments on commit da15aaf

Please sign in to comment.