Skip to content

Commit b567466

Browse files
committed
Upgrade mix ModularStartup configuration to use .NET HostingStartup
1 parent 6053acc commit b567466

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+608
-694
lines changed

assets/nuglify/Configure.Nuglify.cs

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using ServiceStack.Html;
33
using NUglify;
44

5+
[assembly: HostingStartup(typeof(MyApp.ConfigureNUglify))]
6+
57
namespace MyApp
68
{
79
public class NUglifyJsMinifier : ICompressor
@@ -17,13 +19,13 @@ public class NUglifyHtmlMinifier : ICompressor
1719
public string Compress(string html) => Uglify.Html(html).Code;
1820
}
1921

20-
public class ConfigureNUglify : IConfigureAppHost
22+
public class ConfigureNUglify : IHostingStartup
2123
{
22-
public void Configure(IAppHost appHost)
23-
{
24-
Minifiers.JavaScript = new NUglifyJsMinifier();
25-
Minifiers.Css = new NUglifyCssMinifier();
26-
Minifiers.Html = new NUglifyHtmlMinifier();
27-
}
24+
public void Configure(IWebHostBuilder builder) => builder
25+
.ConfigureAppHost(_ => {
26+
Minifiers.JavaScript = new NUglifyJsMinifier();
27+
Minifiers.Css = new NUglifyCssMinifier();
28+
Minifiers.Html = new NUglifyHtmlMinifier();
29+
});
2830
}
29-
}
31+
}

auth/auth-ext/Configure.Auth.cs

+23-23
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
using ServiceStack.Auth;
44
using ServiceStack.FluentValidation;
55

6+
[assembly: HostingStartup(typeof(MyApp.ConfigureAuth))]
7+
68
namespace MyApp
79
{
810
// Add any additional metadata properties you want to store in the Users Typed Session
911
public class CustomUserSession : AuthUserSession
1012
{
1113
}
1214

13-
// Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
15+
// Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
1416
public class CustomRegistrationValidator : RegistrationValidator
1517
{
1618
public CustomRegistrationValidator()
@@ -23,29 +25,27 @@ public CustomRegistrationValidator()
2325
}
2426
}
2527

26-
public class ConfigureAuth : IConfigureAppHost, IConfigureServices
28+
public class ConfigureAuth : IHostingStartup
2729
{
28-
public void Configure(IServiceCollection services)
29-
{
30-
//services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
31-
}
30+
public void Configure(IWebHostBuilder builder) => builder
31+
.ConfigureServices(services => {
32+
//services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
33+
})
34+
.ConfigureAppHost(appHost => {
35+
var appSettings = appHost.AppSettings;
36+
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
37+
new IAuthProvider[] {
38+
new CredentialsAuthProvider(appSettings), /* Sign In with Username / Password credentials */
39+
new AppleAuthProvider(appSettings), /* Configure: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple */
40+
new FacebookAuthProvider(appSettings), /* Create App https://developers.facebook.com/apps */
41+
new GoogleAuthProvider(appSettings), /* Create App https://console.developers.google.com/apis/credentials */
42+
new MicrosoftGraphAuthProvider(appSettings), /* Create App https://apps.dev.microsoft.com */
43+
}));
3244

33-
public void Configure(IAppHost appHost)
34-
{
35-
var AppSettings = appHost.AppSettings;
36-
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
37-
new IAuthProvider[] {
38-
new CredentialsAuthProvider(AppSettings), /* Sign In with Username / Password credentials */
39-
new AppleAuthProvider(AppSettings), /* Configure: https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple */
40-
new FacebookAuthProvider(AppSettings), /* Create App https://developers.facebook.com/apps */
41-
new GoogleAuthProvider(AppSettings), /* Create App https://console.developers.google.com/apis/credentials */
42-
new MicrosoftGraphAuthProvider(AppSettings), /* Create App https://apps.dev.microsoft.com */
43-
}));
45+
appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service
4446

45-
appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service
46-
47-
//override the default registration validation with your own custom implementation
48-
appHost.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();
49-
}
47+
//override the default registration validation with your own custom implementation
48+
appHost.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();
49+
});
5050
}
51-
}
51+
}

auth/auth/Configure.Auth.cs

+22-22
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
using ServiceStack.Auth;
44
using ServiceStack.FluentValidation;
55

6+
[assembly: HostingStartup(typeof(MyApp.ConfigureAuth))]
7+
68
namespace MyApp
79
{
810
// Add any additional metadata properties you want to store in the Users Typed Session
911
public class CustomUserSession : AuthUserSession
1012
{
1113
}
1214

13-
// Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
15+
// Custom Validator to add custom validators to built-in /register Service requiring DisplayName and ConfirmPassword
1416
public class CustomRegistrationValidator : RegistrationValidator
1517
{
1618
public CustomRegistrationValidator()
@@ -23,28 +25,26 @@ public CustomRegistrationValidator()
2325
}
2426
}
2527

26-
public class ConfigureAuth : IConfigureAppHost, IConfigureServices
28+
public class ConfigureAuth : IHostingStartup
2729
{
28-
public void Configure(IServiceCollection services)
29-
{
30-
//services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
31-
}
30+
public void Configure(IWebHostBuilder builder) => builder
31+
.ConfigureServices(services => {
32+
//services.AddSingleton<ICacheClient>(new MemoryCacheClient()); //Store User Sessions in Memory Cache (default)
33+
})
34+
.ConfigureAppHost(appHost => {
35+
var appSettings = appHost.AppSettings;
36+
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
37+
new IAuthProvider[] {
38+
new CredentialsAuthProvider(appSettings), /* Sign In with Username / Password credentials */
39+
new FacebookAuthProvider(appSettings), /* Create App https://developers.facebook.com/apps */
40+
new GoogleAuthProvider(appSettings), /* Create App https://console.developers.google.com/apis/credentials */
41+
new MicrosoftGraphAuthProvider(appSettings), /* Create App https://apps.dev.microsoft.com */
42+
}));
3243

33-
public void Configure(IAppHost appHost)
34-
{
35-
var AppSettings = appHost.AppSettings;
36-
appHost.Plugins.Add(new AuthFeature(() => new CustomUserSession(),
37-
new IAuthProvider[] {
38-
new CredentialsAuthProvider(AppSettings), /* Sign In with Username / Password credentials */
39-
new FacebookAuthProvider(AppSettings), /* Create App https://developers.facebook.com/apps */
40-
new GoogleAuthProvider(AppSettings), /* Create App https://console.developers.google.com/apis/credentials */
41-
new MicrosoftGraphAuthProvider(AppSettings), /* Create App https://apps.dev.microsoft.com */
42-
}));
44+
appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service
4345

44-
appHost.Plugins.Add(new RegistrationFeature()); //Enable /register Service
45-
46-
//override the default registration validation with your own custom implementation
47-
appHost.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();
48-
}
46+
//override the default registration validation with your own custom implementation
47+
appHost.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();
48+
});
4949
}
50-
}
50+
}

auth/db/Configure.AuthRepository.cs

+12-22
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using Microsoft.Extensions.DependencyInjection;
41
using ServiceStack;
52
using ServiceStack.Web;
63
using ServiceStack.Data;
74
using ServiceStack.Auth;
85
using ServiceStack.Configuration;
9-
using ServiceStack.OrmLite;
6+
7+
[assembly: HostingStartup(typeof(MyApp.ConfigureAuthRepository))]
108

119
namespace MyApp
1210
{
@@ -35,27 +33,19 @@ public override void OnAuthenticated(IRequest req, IAuthSession session, IServic
3533
}
3634
}
3735

38-
public class ConfigureAuthRepository : IConfigureAppHost, IConfigureServices, IPreInitPlugin
36+
public class ConfigureAuthRepository : IHostingStartup
3937
{
40-
public void Configure(IServiceCollection services)
41-
{
42-
services.AddSingleton<IAuthRepository>(c =>
38+
public void Configure(IWebHostBuilder builder) => builder
39+
.ConfigureServices(services => services.AddSingleton<IAuthRepository>(c =>
4340
new OrmLiteAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IDbConnectionFactory>()) {
4441
UseDistinctRoleTables = true
45-
});
46-
}
47-
48-
public void Configure(IAppHost appHost)
49-
{
50-
var authRepo = appHost.Resolve<IAuthRepository>();
51-
authRepo.InitSchema();
52-
//CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
53-
}
54-
55-
public void BeforePluginsLoaded(IAppHost appHost)
56-
{
57-
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents());
58-
}
42+
}))
43+
.ConfigureAppHost(appHost => {
44+
var authRepo = appHost.Resolve<IAuthRepository>();
45+
authRepo.InitSchema();
46+
// CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
47+
}, afterConfigure: appHost =>
48+
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents()));
5949

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

auth/dynamodb/Configure.AuthRepository.cs

+14-25
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using Microsoft.Extensions.DependencyInjection;
41
using ServiceStack;
52
using ServiceStack.Web;
3+
using ServiceStack.Data;
64
using ServiceStack.Auth;
75
using ServiceStack.Configuration;
8-
using ServiceStack.Aws;
9-
using ServiceStack.Aws.DynamoDb;
6+
7+
[assembly: HostingStartup(typeof(MyApp.ConfigureAuthRepository))]
108

119
namespace MyApp
1210
{
13-
// Custom UserAuth Data Model with extended Metadata properties
11+
// Custom User Table with extended Metadata properties
1412
public class AppUser : UserAuth
1513
{
1614
public string ProfileUrl { get; set; }
@@ -35,26 +33,17 @@ public override void OnAuthenticated(IRequest req, IAuthSession session, IServic
3533
}
3634
}
3735

38-
public class ConfigureAuthRepository : IConfigureAppHost, IConfigureServices, IPreInitPlugin
36+
public class ConfigureAuthRepository : IHostingStartup
3937
{
40-
public void Configure(IServiceCollection services)
41-
{
42-
services.AddSingleton<IAuthRepository>(c =>
43-
new DynamoDbAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IPocoDynamo>()));
44-
}
45-
46-
public void Configure(IAppHost appHost)
47-
{
48-
var authRepo = appHost.Resolve<IAuthRepository>();
49-
authRepo.InitSchema();
50-
51-
//CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
52-
}
53-
54-
public void BeforePluginsLoaded(IAppHost appHost)
55-
{
56-
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents());
57-
}
38+
public void Configure(IWebHostBuilder builder) => builder
39+
.ConfigureServices(services => services.AddSingleton<IAuthRepository>(c =>
40+
new DynamoDbAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IPocoDynamo>())))
41+
.ConfigureAppHost(appHost => {
42+
var authRepo = appHost.Resolve<IAuthRepository>();
43+
authRepo.InitSchema();
44+
// CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
45+
}, afterConfigure: appHost =>
46+
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents()));
5847

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

auth/marten/Configure.AuthRepository.cs

+13-20
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
using Marten;
99
using ServiceStack.Authentication.Marten;
1010

11+
[assembly: HostingStartup(typeof(MyApp.ConfigureAuthRepository))]
12+
1113
namespace MyApp
1214
{
13-
// Custom UserAuth Data Model with extended Metadata properties
15+
// Custom User Table with extended Metadata properties
1416
public class AppUser : UserAuth
1517
{
1618
public string ProfileUrl { get; set; }
@@ -35,7 +37,7 @@ public override void OnAuthenticated(IRequest req, IAuthSession session, IServic
3537
}
3638
}
3739

38-
public class ConfigureAuthRepository : IConfigureAppHost, IConfigureServices, IPreInitPlugin
40+
public class ConfigureAuthRepository : IHostingStartup
3941
{
4042
static ConfigureAuthRepository()
4143
{
@@ -46,24 +48,15 @@ static ConfigureAuthRepository()
4648
});
4749
}
4850

49-
public void Configure(IServiceCollection services)
50-
{
51-
services.AddSingleton<IAuthRepository>(c =>
52-
new MartenAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IDocumentStore>()));
53-
}
54-
55-
public void Configure(IAppHost appHost)
56-
{
57-
var authRepo = appHost.Resolve<IAuthRepository>();
58-
authRepo.InitSchema();
59-
60-
//CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
61-
}
62-
63-
public void BeforePluginsLoaded(IAppHost appHost)
64-
{
65-
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents());
66-
}
51+
public void Configure(IWebHostBuilder builder) => builder
52+
.ConfigureServices(services => services.AddSingleton<IAuthRepository>(c =>
53+
new MartenAuthRepository<AppUser, UserAuthDetails>(c.Resolve<IDocumentStore>())))
54+
.ConfigureAppHost(appHost => {
55+
var authRepo = appHost.Resolve<IAuthRepository>();
56+
authRepo.InitSchema();
57+
// CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
58+
}, afterConfigure: appHost =>
59+
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents()));
6760

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

auth/memory/Configure.AuthRepository.cs

+13-23
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using Microsoft.Extensions.DependencyInjection;
41
using ServiceStack;
52
using ServiceStack.Web;
63
using ServiceStack.Auth;
74
using ServiceStack.Configuration;
85

6+
[assembly: HostingStartup(typeof(MyApp.ConfigureAuthRepository))]
7+
98
namespace MyApp
109
{
11-
// Custom UserAuth Data Model with extended Metadata properties
10+
// Custom User Table with extended Metadata properties
1211
public class AppUser : UserAuth
1312
{
1413
public string ProfileUrl { get; set; }
@@ -33,26 +32,17 @@ public override void OnAuthenticated(IRequest req, IAuthSession session, IServic
3332
}
3433
}
3534

36-
public class ConfigureAuthRepository : IConfigureAppHost, IConfigureServices, IPreInitPlugin
35+
public class ConfigureAuthRepository : IHostingStartup
3736
{
38-
public void Configure(IServiceCollection services)
39-
{
40-
services.AddSingleton<IAuthRepository>(c =>
41-
new InMemoryAuthRepository<AppUser, UserAuthDetails>());
42-
}
43-
44-
public void Configure(IAppHost appHost)
45-
{
46-
var authRepo = appHost.Resolve<IAuthRepository>();
47-
authRepo.InitSchema();
48-
49-
//CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
50-
}
51-
52-
public void BeforePluginsLoaded(IAppHost appHost)
53-
{
54-
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents());
55-
}
37+
public void Configure(IWebHostBuilder builder) => builder
38+
.ConfigureServices(services => services.AddSingleton<IAuthRepository>(c =>
39+
new InMemoryAuthRepository<AppUser, UserAuthDetails>()))
40+
.ConfigureAppHost(appHost => {
41+
var authRepo = appHost.Resolve<IAuthRepository>();
42+
authRepo.InitSchema();
43+
// CreateUser(authRepo, "admin@email.com", "Admin User", "p@55wOrd", roles:new[]{ RoleNames.Admin });
44+
}, afterConfigure: appHost =>
45+
appHost.AssertPlugin<AuthFeature>().AuthEvents.Add(new AppUserAuthEvents()));
5646

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

0 commit comments

Comments
 (0)