Skip to content

Commit

Permalink
Upgrade mix ModularStartup configuration to use .NET HostingStartup
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Nov 11, 2021
1 parent 6053acc commit b567466
Show file tree
Hide file tree
Showing 44 changed files with 608 additions and 694 deletions.
18 changes: 10 additions & 8 deletions assets/nuglify/Configure.Nuglify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using ServiceStack.Html;
using NUglify;

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

namespace MyApp
{
public class NUglifyJsMinifier : ICompressor
Expand All @@ -17,13 +19,13 @@ public class NUglifyHtmlMinifier : ICompressor
public string Compress(string html) => Uglify.Html(html).Code;
}

public class ConfigureNUglify : IConfigureAppHost
public class ConfigureNUglify : IHostingStartup
{
public void Configure(IAppHost appHost)
{
Minifiers.JavaScript = new NUglifyJsMinifier();
Minifiers.Css = new NUglifyCssMinifier();
Minifiers.Html = new NUglifyHtmlMinifier();
}
public void Configure(IWebHostBuilder builder) => builder
.ConfigureAppHost(_ => {
Minifiers.JavaScript = new NUglifyJsMinifier();
Minifiers.Css = new NUglifyCssMinifier();
Minifiers.Html = new NUglifyHtmlMinifier();
});
}
}
}
46 changes: 23 additions & 23 deletions auth/auth-ext/Configure.Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
using ServiceStack.Auth;
using ServiceStack.FluentValidation;

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

namespace MyApp
{
// Add any additional metadata properties you want to store in the Users Typed Session
public class CustomUserSession : AuthUserSession
{
}

// Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
// Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
public class CustomRegistrationValidator : RegistrationValidator
{
public CustomRegistrationValidator()
Expand All @@ -23,29 +25,27 @@ public CustomRegistrationValidator()
}
}

public class ConfigureAuth : IConfigureAppHost, IConfigureServices
public class ConfigureAuth : IHostingStartup
{
public void Configure(IServiceCollection services)
{
//services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
}
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => {
//services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
})
.ConfigureAppHost(appHost => {
var appSettings = appHost.AppSettings;
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(appSettings), /* Sign In with Username / Password credentials */
new AppleAuthProvider(appSettings), /* Configure: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple */
new FacebookAuthProvider(appSettings), /* Create App https://developers.facebook.com/apps */
new GoogleAuthProvider(appSettings), /* Create App https://console.developers.google.com/apis/credentials */
new MicrosoftGraphAuthProvider(appSettings), /* Create App https://apps.dev.microsoft.com */
}));
public void Configure(IAppHost appHost)
{
var AppSettings = appHost.AppSettings;
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(AppSettings), /* Sign In with Username / Password credentials */
new AppleAuthProvider(AppSettings), /* Configure: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple */
new FacebookAuthProvider(AppSettings), /* Create App https://developers.facebook.com/apps */
new GoogleAuthProvider(AppSettings), /* Create App https://console.developers.google.com/apis/credentials */
new MicrosoftGraphAuthProvider(AppSettings), /* Create App https://apps.dev.microsoft.com */
}));
appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service
appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service

//override the default registration validation with your own custom implementation
appHost.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();
}
//override the default registration validation with your own custom implementation
appHost.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();
});
}
}
}
44 changes: 22 additions & 22 deletions auth/auth/Configure.Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
using ServiceStack.Auth;
using ServiceStack.FluentValidation;

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

namespace MyApp
{
// Add any additional metadata properties you want to store in the Users Typed Session
public class CustomUserSession : AuthUserSession
{
}

// Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
// Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
public class CustomRegistrationValidator : RegistrationValidator
{
public CustomRegistrationValidator()
Expand All @@ -23,28 +25,26 @@ public CustomRegistrationValidator()
}
}

public class ConfigureAuth : IConfigureAppHost, IConfigureServices
public class ConfigureAuth : IHostingStartup
{
public void Configure(IServiceCollection services)
{
//services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
}
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => {
//services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
})
.ConfigureAppHost(appHost => {
var appSettings = appHost.AppSettings;
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(appSettings), /* Sign In with Username / Password credentials */
new FacebookAuthProvider(appSettings), /* Create App https://developers.facebook.com/apps */
new GoogleAuthProvider(appSettings), /* Create App https://console.developers.google.com/apis/credentials */
new MicrosoftGraphAuthProvider(appSettings), /* Create App https://apps.dev.microsoft.com */
}));
public void Configure(IAppHost appHost)
{
var AppSettings = appHost.AppSettings;
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
new IAuthProvider[] {
new CredentialsAuthProvider(AppSettings), /* Sign In with Username / Password credentials */
new FacebookAuthProvider(AppSettings), /* Create App https://developers.facebook.com/apps */
new GoogleAuthProvider(AppSettings), /* Create App https://console.developers.google.com/apis/credentials */
new MicrosoftGraphAuthProvider(AppSettings), /* Create App https://apps.dev.microsoft.com */
}));
appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service
appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service

//override the default registration validation with your own custom implementation
appHost.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();
}
//override the default registration validation with your own custom implementation
appHost.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();
});
}
}
}
34 changes: 12 additions & 22 deletions auth/db/Configure.AuthRepository.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack;
using ServiceStack.Web;
using ServiceStack.Data;
using ServiceStack.Auth;
using ServiceStack.Configuration;
using ServiceStack.OrmLite;

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

namespace MyApp
{
Expand Down Expand Up @@ -35,27 +33,19 @@ public override void OnAuthenticated(IRequest req, IAuthSession session, IServic
}
}

public class ConfigureAuthRepository : IConfigureAppHost, IConfigureServices, IPreInitPlugin
public class ConfigureAuthRepository : IHostingStartup
{
public void Configure(IServiceCollection services)
{
services.AddSingleton<IAuthRepository>(c =>
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => services.AddSingleton<IAuthRepository>(c =>
new OrmLiteAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IDbConnectionFactory>()) {
UseDistinctRoleTables = true
});
}

public void Configure(IAppHost appHost)
{
var authRepo = appHost.Resolve<IAuthRepository>();
authRepo.InitSchema();
//CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
}

public void BeforePluginsLoaded(IAppHost appHost)
{
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents());
}
}))
.ConfigureAppHost(appHost => {
var authRepo = appHost.Resolve<IAuthRepository>();
authRepo.InitSchema();
// CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
}, afterConfigure: appHost =>
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents()));

// Add initial Users to the configured Auth Repository
public void CreateUser(IAuthRepository authRepo, string email, string name, string password, string[] roles)
Expand Down
39 changes: 14 additions & 25 deletions auth/dynamodb/Configure.AuthRepository.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack;
using ServiceStack.Web;
using ServiceStack.Data;
using ServiceStack.Auth;
using ServiceStack.Configuration;
using ServiceStack.Aws;
using ServiceStack.Aws.DynamoDb;

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

namespace MyApp
{
// Custom UserAuth Data Model with extended Metadata properties
// Custom User Table with extended Metadata properties
public class AppUser : UserAuth
{
public string ProfileUrl { get; set; }
Expand All @@ -35,26 +33,17 @@ public override void OnAuthenticated(IRequest req, IAuthSession session, IServic
}
}

public class ConfigureAuthRepository : IConfigureAppHost, IConfigureServices, IPreInitPlugin
public class ConfigureAuthRepository : IHostingStartup
{
public void Configure(IServiceCollection services)
{
services.AddSingleton<IAuthRepository>(c =>
new DynamoDbAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IPocoDynamo>()));
}

public void Configure(IAppHost appHost)
{
var authRepo = appHost.Resolve<IAuthRepository>();
authRepo.InitSchema();

//CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
}

public void BeforePluginsLoaded(IAppHost appHost)
{
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents());
}
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => services.AddSingleton<IAuthRepository>(c =>
new DynamoDbAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IPocoDynamo>())))
.ConfigureAppHost(appHost => {
var authRepo = appHost.Resolve<IAuthRepository>();
authRepo.InitSchema();
// CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
}, afterConfigure: appHost =>
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents()));

// Add initial Users to the configured Auth Repository
public void CreateUser(IAuthRepository authRepo, string email, string name, string password, string[] roles)
Expand Down
33 changes: 13 additions & 20 deletions auth/marten/Configure.AuthRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
using Marten;
using ServiceStack.Authentication.Marten;

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

namespace MyApp
{
// Custom UserAuth Data Model with extended Metadata properties
// Custom User Table with extended Metadata properties
public class AppUser : UserAuth
{
public string ProfileUrl { get; set; }
Expand All @@ -35,7 +37,7 @@ public override void OnAuthenticated(IRequest req, IAuthSession session, IServic
}
}

public class ConfigureAuthRepository : IConfigureAppHost, IConfigureServices, IPreInitPlugin
public class ConfigureAuthRepository : IHostingStartup
{
static ConfigureAuthRepository()
{
Expand All @@ -46,24 +48,15 @@ static ConfigureAuthRepository()
});
}

public void Configure(IServiceCollection services)
{
services.AddSingleton<IAuthRepository>(c =>
new MartenAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IDocumentStore>()));
}

public void Configure(IAppHost appHost)
{
var authRepo = appHost.Resolve<IAuthRepository>();
authRepo.InitSchema();

//CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
}

public void BeforePluginsLoaded(IAppHost appHost)
{
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents());
}
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => services.AddSingleton<IAuthRepository>(c =>
new MartenAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IDocumentStore>())))
.ConfigureAppHost(appHost => {
var authRepo = appHost.Resolve<IAuthRepository>();
authRepo.InitSchema();
// CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
}, afterConfigure: appHost =>
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents()));

// Add initial Users to the configured Auth Repository
public void CreateUser(IAuthRepository authRepo, string email, string name, string password, string[] roles)
Expand Down
36 changes: 13 additions & 23 deletions auth/memory/Configure.AuthRepository.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack;
using ServiceStack.Web;
using ServiceStack.Auth;
using ServiceStack.Configuration;

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

namespace MyApp
{
// Custom UserAuth Data Model with extended Metadata properties
// Custom User Table with extended Metadata properties
public class AppUser : UserAuth
{
public string ProfileUrl { get; set; }
Expand All @@ -33,26 +32,17 @@ public override void OnAuthenticated(IRequest req, IAuthSession session, IServic
}
}

public class ConfigureAuthRepository : IConfigureAppHost, IConfigureServices, IPreInitPlugin
public class ConfigureAuthRepository : IHostingStartup
{
public void Configure(IServiceCollection services)
{
services.AddSingleton<IAuthRepository>(c =>
new InMemoryAuthRepository<AppUser, UserAuthDetails>());
}

public void Configure(IAppHost appHost)
{
var authRepo = appHost.Resolve<IAuthRepository>();
authRepo.InitSchema();

//CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
}

public void BeforePluginsLoaded(IAppHost appHost)
{
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents());
}
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices(services => services.AddSingleton<IAuthRepository>(c =>
new InMemoryAuthRepository<AppUser, UserAuthDetails>()))
.ConfigureAppHost(appHost => {
var authRepo = appHost.Resolve<IAuthRepository>();
authRepo.InitSchema();
// CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
}, afterConfigure: appHost =>
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents()));

// Add initial Users to the configured Auth Repository
public void CreateUser(IAuthRepository authRepo, string email, string name, string password, string[] roles)
Expand Down
Loading

0 comments on commit b567466

Please sign in to comment.