Skip to content

Commit 8a3f3dd

Browse files
committed
Upgrade to use recommended Plugin syntax
1 parent fd92a02 commit 8a3f3dd

File tree

11 files changed

+100
-99
lines changed

11 files changed

+100
-99
lines changed

MyApp/_pages/autoquery/autogen.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You can then add the generated DTOs to your ServiceModel's to quickly enable Aut
2121
To enable this feature you you just need to initialize `GenerateCrudServices` in your `AutoQueryFeature` plugin, e.g:
2222

2323
```csharp
24-
Plugins.Add(new AutoQueryFeature {
24+
services.AddPlugin(new AutoQueryFeature {
2525
MaxLimit = 1000,
2626
GenerateCrudServices = new GenerateCrudServices {}
2727
});
@@ -55,15 +55,12 @@ public class ConfigureDb : IHostingStartup
5555
{
5656
public void Configure(IWebHostBuilder builder) => builder
5757
.ConfigureServices((context, services) => {
58-
var dbFactory = new OrmLiteConnectionFactory(
59-
context.Configuration.GetConnectionString("DefaultConnection"),
60-
SqliteDialect.Provider);
61-
container.AddSingleton<IDbConnectionFactory>(c => dbFactory);
58+
var ormLite = services.AddOrmLite(options => options.UseSqlite(connString));
6259

6360
services.AddPlugin(new AutoQueryFeature {
6461
MaxLimit = 1000,
6562
GenerateCrudServices = new GenerateCrudServices {
66-
DbFactory = dbFactory,
63+
DbFactory = ormLite.DbFactory,
6764
}
6865
});
6966
// ...
@@ -120,7 +117,7 @@ i.e. the same experience as updating normal DTOs.
120117
After generating `dtos.cs` AutoGen is no longer needed and can now be removed by removing `GenerateCrudServices`
121118

122119
```csharp
123-
Plugins.Add(new AutoQueryFeature {
120+
services.AddPlugin(new AutoQueryFeature {
124121
MaxLimit = 1000,
125122
// GenerateCrudServices = new GenerateCrudServices {}
126123
});
@@ -203,9 +200,11 @@ But we can raise the productivity level even higher by instead of manually impor
203200
This is what the magical `AutoRegister` flag does for us:
204201

205202
```csharp
206-
Plugins.Add(new AutoQueryFeature {
203+
var ormLite = services.AddOrmLite(options => options.UseSqlite(connString));
204+
205+
services.AddPlugin(new AutoQueryFeature {
207206
GenerateCrudServices = new GenerateCrudServices {
208-
DbFactory = dbFactory,
207+
DbFactory = ormLite.DbFactory,
209208
AutoRegister = true,
210209
//....
211210
}
@@ -247,16 +246,12 @@ public class ConfigureDb : IHostingStartup
247246
{
248247
builder.ConfigureServices((context,services) =>
249248
{
250-
var dbFactory = new OrmLiteConnectionFactory(
251-
context.Configuration.GetConnectionString("DefaultConnection"),
252-
SqliteDialect.Provider);
253-
254-
services.AddSingleton<IDbConnectionFactory>(dbFactory);
249+
var ormLite = services.AddOrmLite(options => options.UseSqlite(connString));
255250

256251
services.AddPlugin(new AutoQueryFeature {
257252
MaxLimit = 1000,
258253
GenerateCrudServices = new GenerateCrudServices {
259-
DbFactory = dbFactory,
254+
DbFactory = ormLite.DbFactory,
260255
AutoRegister = true
261256
}
262257
});
@@ -433,8 +428,11 @@ The primary difference is that they only exist in a .NET Assembly in memory crea
433428
Peeking deeper behind the `AutoRegister` flag will reveal that it's a helper for adding an empty `CreateCrudServices` instance, i.e. it's equivalent to:
434429

435430
```csharp
436-
Plugins.Add(new AutoQueryFeature {
431+
var ormLite = services.AddOrmLite(options => options.UseSqlite(connString));
432+
433+
services.AddPlugin(new AutoQueryFeature {
437434
GenerateCrudServices = new GenerateCrudServices {
435+
DbFactory = ormLite.DbFactory,
438436
CreateServices = {
439437
new CreateCrudServices()
440438
}
@@ -452,9 +450,11 @@ Although should you wish to, you can also generate Services for multiple Databas
452450
With this you could have a single API Gateway Servicifying access to multiple System RDBMS Tables & Schemas, e.g:
453451

454452
```csharp
455-
Plugins.Add(new AutoQueryFeature {
453+
var ormLite = services.AddOrmLite(options => options.UseSqlite(connString));
454+
455+
services.AddPlugin(new AutoQueryFeature {
456456
GenerateCrudServices = new GenerateCrudServices {
457-
DbFactory = dbFactory,
457+
DbFactory = ormlite.DbFactory,
458458
CreateServices = {
459459
new CreateCrudServices(),
460460
new CreateCrudServices { Schema = "AltSchema" },
@@ -505,7 +505,7 @@ var tableRequiredFields = new Dictionary<string,string[]> {
505505
["Shipper"] = new[]{ "CompanyName", "Phone" },
506506
};
507507
508-
Plugins.Add(new AutoQueryFeature {
508+
services.AddPlugin(new AutoQueryFeature {
509509
MaxLimit = 100,
510510
GenerateCrudServices = new GenerateCrudServices
511511
{
@@ -552,16 +552,16 @@ Plugins.Add(new AutoQueryFeature {
552552
IncludeType = type => !ignoreTables.Contains(type.Name),
553553
}
554554
});
555-
556-
Plugins.Add(new ValidationFeature()); // Enable Validation
557555
```
558556

559557
Additionally, the `TableSchemasFilter` can be used to modify the schema used by AutoGen to generate the types associated with your AutoQuery APIs.
560558
This gives you the opportunity to filter or modify the schema after they are pulled from the database.
561559
For example, we could `Remove` tables based on naming, or alter column definitions to assist with any schema issues.
562560

563561
```csharp
562+
var ormLite = services.AddOrmLite(options => options.UseSqlite(connString));
564563
GenerateCrudServices = new GenerateCrudServices {
564+
DbFactory = ormLite.DbFactory,
565565
AutoRegister = true,
566566
AddDataContractAttributes = false,
567567
TableSchemasFilter = tableSchemas =>
@@ -671,10 +671,12 @@ So if you had an existing table name called `applications` the default conventio
671671
You can change each of these default conventions with the new `GenerateOperationsFilter`, e.g:
672672

673673
```csharp
674-
Plugins.Add(new AutoQueryFeature {
674+
var ormLite = services.AddOrmLite(options => options.UseSqlite(connString));
675+
676+
services.AddPlugin(new AutoQueryFeature {
675677
MaxLimit = 1000,
676678
GenerateCrudServices = new GenerateCrudServices {
677-
DbFactory = dbFactory,
679+
DbFactory = ormLite.DbFactory,
678680
AutoRegister = true,
679681
GenerateOperationsFilter = ctx => {
680682
if (ctx.TableName == "applications")

MyApp/_pages/autoquery/crud.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,7 @@ public class QueryRockstarAudit : QueryDbTenant<RockstarAuditTenant, Rockstar>
550550
}
551551
```
552552

553-
To coincide with AutoCRUD there's also support for [declarative validation](https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.Endpoints.Tests/AutoQueryCrudTests.Validate.cs) which thanks to [#Script](https://sharpscript.net/) lets you define your Fluent Validation Rules by annotating your Request DTO properties. As it's essentially a different way to define Fluent Validation Rules, it still [needs Validation enabled](/validation#validation-feature) to run:
554-
555-
```csharp
556-
Plugins.Add(new ValidationFeature());
557-
```
553+
To coincide with AutoCRUD there's also support for [declarative validation](https://github.com/ServiceStack/ServiceStack/blob/master/tests/ServiceStack.WebHost.Endpoints.Tests/AutoQueryCrudTests.Validate.cs) which thanks to [#Script](https://sharpscript.net/) lets you define your Fluent Validation Rules by annotating your Request DTO properties. As it's essentially a different way to define Fluent Validation Rules, it still [needs Validation enabled](/validation#validation-feature).
558554

559555
### AutoMap and AutoDefault Attributes
560556

@@ -735,7 +731,7 @@ void MyAuditFilter(AutoCrudMetadata meta)
735731
}
736732
}
737733

738-
Plugins.Add(new AutoQueryFeature {
734+
services.AddPlugin(new AutoQueryFeature {
739735
AutoCrudMetadataFilters = { MyAuditFilter },
740736
});
741737
```
@@ -745,7 +741,7 @@ Plugins.Add(new AutoQueryFeature {
745741
AutoQuery includes `OnBefore*` and `OnAfter*` (sync & async) events for `Create`, `Update`, `Patch` & `Delete` that can be used to execute custom logic before or after each AutoQuery CRUD operation. E.g. if your system implements their own Audit history via RDBMS triggers, you can use the `OnBefore` **Delete** event to update the record with deleted info before the AutoQuery CRUD operation deletes it:
746742

747743
```csharp
748-
Plugins.Add(new AutoQueryFeature {
744+
services.AddPlugin(new AutoQueryFeature {
749745
OnBeforeDeleteAsync = async ctx => {
750746
if (ctx.Dto is DeleteBooking deleteBooking)
751747
{

MyApp/_pages/autoquery/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ container.AddSingleton<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(
166166
MapProjectPath("~/northwind.sqlite"), SqliteDialect.Provider));
167167

168168
// Add the AutoQuery Plugin
169-
Plugins.Add(new AutoQueryFeature {
169+
services.AddPlugin(new AutoQueryFeature {
170170
MaxLimit = 1000
171171
});
172172
```
@@ -247,7 +247,7 @@ container.AddSingleton<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(
247247
MapProjectPath("~/northwind.sqlite"), SqliteDialect.Provider));
248248

249249
// Configure AutoQuery to Generate CRUD services
250-
Plugins.Add(new AutoQueryFeature {
250+
services.AddPlugin(new AutoQueryFeature {
251251
MaxLimit = 1000,
252252
GenerateCrudServices = new GenerateCrudServices {
253253
AutoRegister = true

MyApp/_pages/autoquery/rdbms.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ In addition to leveraging ServiceStack's existing functionality, maximizing re-u
1515
Like ServiceStack's [other composable features](/plugins), the AutoQuery Feature is enabled by registering a Plugin, e.g:
1616

1717
```csharp
18-
Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });
18+
services.AddPlugin(new AutoQueryFeature { MaxLimit = 100 });
1919
```
2020

2121
Which is all that's needed to enable the AutoQuery feature. The AutoQueryFeature is inside [ServiceStack.Server](https://servicestack.net/download#get-started) NuGet package which contains value-added features that utilize either OrmLite and Redis which can be added to your project with:
@@ -658,7 +658,7 @@ Which is why we recommend formalizing your conventions you want to allow before
658658
When publishing your API, you can also assert that only explicit conventions are ever used by disabling untyped implicit conventions support with:
659659

660660
```csharp
661-
Plugins.Add(new AutoQueryFeature { EnableUntypedQueries = false });
661+
services.AddPlugin(new AutoQueryFeature { EnableUntypedQueries = false });
662662
```
663663

664664
## Raw SQL Filters
@@ -670,7 +670,7 @@ Raw SQL Filters also don't benefit from limiting matching to declared fields and
670670
If safe to do so, RawSqlFilters can be enabled with:
671671

672672
```csharp
673-
Plugins.Add(new AutoQueryFeature {
673+
services.AddPlugin(new AutoQueryFeature {
674674
EnableRawSqlFilters = true,
675675
UseNamedConnection = "readonly",
676676
IllegalSqlFragmentTokens = { "ProtectedSqlFunction" },
@@ -805,7 +805,7 @@ client.Get(new QueryRockstars { Skip=10, Take=20, OrderByDesc="Id" });
805805
Or remove the default behavior with:
806806

807807
```csharp
808-
Plugins.Add(new AutoQueryFeature {
808+
services.AddPlugin(new AutoQueryFeature {
809809
OrderByPrimaryKeyOnPagedQuery = false
810810
});
811811
```
@@ -961,7 +961,7 @@ AVG, COUNT, FIRST, LAST, MAX, MIN, SUM
961961
Which can be added to or removed from by modifying `SqlAggregateFunctions` collection, e.g, you can allow usage of a `CustomAggregate` SQL Function with:
962962

963963
```cs
964-
Plugins.Add(new AutoQueryFeature {
964+
services.AddPlugin(new AutoQueryFeature {
965965
SqlAggregateFunctions = { "CustomAggregate" }
966966
})
967967
```
@@ -1038,7 +1038,7 @@ var response = client.Get(new MyQuery { Include = "Total" });
10381038
Alternatively you can always have the Total returned in every request with:
10391039

10401040
```csharp
1041-
Plugins.Add(new AutoQueryFeature {
1041+
services.AddPlugin(new AutoQueryFeature {
10421042
IncludeTotal = true
10431043
})
10441044
```
@@ -1204,7 +1204,7 @@ public class MyReportingServices(IAutoQueryDb autoQuery) : Service
12041204
The Aggregate functions feature is built on the new `ResponseFilters` support in AutoQuery which provides a new extensibility option enabling customization and additional metadata to be attached to AutoQuery Responses. As the Aggregate Functions support is itself a Response Filter in can disabled by clearing them:
12051205

12061206
```csharp
1207-
Plugins.Add(new AutoQueryFeature {
1207+
services.AddPlugin(new AutoQueryFeature {
12081208
ResponseFilters = new List<Action<QueryFilterContext>>()
12091209
})
12101210
```
@@ -1236,7 +1236,7 @@ class Command
12361236
With this we could add basic calculator functionality to AutoQuery with the custom Response Filter below:
12371237

12381238
```csharp
1239-
Plugins.Add(new AutoQueryFeature {
1239+
services.AddPlugin(new AutoQueryFeature {
12401240
ResponseFilters = {
12411241
ctx => {
12421242
var supportedFns = new Dictionary<string, Func<int, int, int>>(StringComparer.OrdinalIgnoreCase)
@@ -1354,7 +1354,7 @@ var autoQuery = new AutoQueryFeature()
13541354
q.And(x => x.LastName.EndsWith("son"))
13551355
);
13561356

1357-
Plugins.Add(autoQuery);
1357+
services.AddPlugin(autoQuery);
13581358
```
13591359

13601360
Registering an interface like `IFilterRockstars` is especially useful as it enables applying custom logic to a number of different Query Services sharing the same interface.
@@ -1385,7 +1385,7 @@ public abstract class MyAutoQueryServiceBase : AutoQueryServiceBase
13851385
Then tell AutoQuery to use your base class instead, e.g:
13861386

13871387
```csharp
1388-
Plugins.Add(new AutoQueryFeature {
1388+
services.AddPlugin(new AutoQueryFeature {
13891389
AutoQueryServiceBaseType = typeof(MyAutoQueryServiceBase)
13901390
});
13911391
```
@@ -1414,7 +1414,7 @@ All AutoQuery CRUD operations support auto batch implementations which will by d
14141414
By default it will generate AutoBatch implementations for all CRUD operations and can be changed to only generate implementations for specific CRUD operations by changing:
14151415

14161416
```csharp
1417-
Plugins.Add(new AutoQueryFeature {
1417+
services.AddPlugin(new AutoQueryFeature {
14181418
GenerateAutoBatchImplementationsFor = new() { AutoCrudOperation.Create }
14191419
});
14201420
```

MyApp/_pages/host-configuration.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,25 @@ title: AppHost Configuration
1414
All ServiceStack App's are configured within an AppHost which typically consists of the following elements:
1515

1616
```csharp
17-
public class AppHost
18-
: AppHostBase // Type of AppHost used, normally AppHostBase
17+
// Service Name in Metadata Pages
18+
public class AppHost() : AppHostBase("MyApp"), IHostingStartup
1919
{
20-
public AppHost() : base(
21-
"MyApp", // Service Name in Metadata Pages
22-
typeof(MyServices).Assembly) {} // The ServiceInterfaces Assemblies where all Services are located
20+
public void Configure(IWebHostBuilder builder) => builder
21+
.ConfigureServices((context, services) => {
22+
// Configure ASP.NET Core IOC Dependencies
23+
services.AddSingleton<IRedisClientsManager>(c => new RedisManagerPool());
24+
25+
// Add Plugins to extend your App with additional functionality
26+
services.AddPlugin(new AutoQueryFeature {
27+
MaxLimit = 100 // Feature specific configuration
28+
});
29+
});
2330

2431
// Configure your AppHost with the necessary configuration and dependencies your App needs
25-
public override void Configure(Container container)
32+
public override void Configure()
2633
{
2734
// Set Global AppHost Configuration
28-
base.SetConfig(new HostConfig
29-
{
30-
DebugMode = AppSettings.Get(nameof(HostConfig.DebugMode), false)
31-
});
32-
33-
//Register IOC Dependencies
34-
container.Register<IRedisClientsManager>(c => new RedisManagerPool());
35-
36-
// Add Plugins to extend your App with additional functionality
37-
Plugins.Add(new AutoQueryFeature {
38-
MaxLimit = 100 // Feature specific configuration
35+
base.SetConfig(new HostConfig {
3936
});
4037
}
4138
}

MyApp/_pages/locode/auditing.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public class ConfigureAutoQuery : IHostingStartup
2626
// Enable Audit History
2727
services.AddSingleton<ICrudEvents>(c =>
2828
new OrmLiteCrudEvents(c.Resolve<IDbConnectionFactory>()));
29-
})
30-
.ConfigureAppHost(appHost => {
31-
appHost.Plugins.Add(new AutoQueryFeature {
29+
30+
services.AddPlugin(new AutoQueryFeature {
3231
MaxLimit = 1000,
3332
//IncludeTotal = true,
34-
});
35-
33+
});
34+
})
35+
.ConfigureAppHost(appHost => {
3636
// Create CrudEvent if it doesn't exist
3737
appHost.Resolve<ICrudEvents>().InitSchema();
3838
});

MyApp/_pages/locode/branding.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ We can add the `[Tag]` attribute to all our Database-First Request DTOs using [A
167167

168168
```cs
169169
GenerateCrudServices = new GenerateCrudServices {
170+
DbFactory = dbFactory,
170171
AutoRegister = true,
171172
ServiceFilter = (op, req) => {
172173
// Annotate all Auto generated Request DTOs with [Tag("Northwind")] attribute

0 commit comments

Comments
 (0)