From 7a05760b2929313c169f545e532487799f71e1cd Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Fri, 5 Jul 2024 22:59:39 +0200 Subject: [PATCH 01/16] Fixing the generation of sorting on queries --- .../Basic/Web/API/Products/AllProducts.ts | 26 +++++++++++++++++++ .../Tools/ProxyGenerator/Templates/Query.hbs | 20 +++++++------- .../Applications/queries/SortingForQuery.ts | 2 +- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts b/Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts index dd2aebf4..f8b76499 100644 --- a/Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts +++ b/Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts @@ -10,14 +10,37 @@ import Handlebars from 'handlebars'; const routeTemplate = Handlebars.compile('/api/products/catalog'); +class AllProductsSortBy { + private _id: SortingForQuery; + private _name: SortingForQuery; + private _isRegistered: SortingForQuery; + + constructor(readonly query: AllProducts) { + this._id = new SortingForQuery('id', query); + this._name = new SortingForQuery('name', query); + this._isRegistered = new SortingForQuery('isRegistered', query); + } + + id(): SortingForQuery { + return this._id; + } + name(): SortingForQuery { + return this._name; + } + isRegistered(): SortingForQuery { + return this._isRegistered; + } +} export class AllProducts extends QueryFor { readonly route: string = '/api/products/catalog'; readonly routeTemplate: Handlebars.TemplateDelegate = routeTemplate; readonly defaultValue: Product[] = []; + readonly _sortBy: AllProductsSortBy; constructor() { super(Product, true); + this._sortBy = new AllProductsSortBy(this); } get requestArguments(): string[] { @@ -25,6 +48,9 @@ export class AllProducts extends QueryFor { ]; } + get sortBy(): AllProductsSortBy { + return this._sortBy; + } static use(): [QueryResultWithState, PerformQuery, SetSorting] { return useQuery(AllProducts); diff --git a/Source/DotNET/Tools/ProxyGenerator/Templates/Query.hbs b/Source/DotNET/Tools/ProxyGenerator/Templates/Query.hbs index 6456f745..bfcdd2e0 100644 --- a/Source/DotNET/Tools/ProxyGenerator/Templates/Query.hbs +++ b/Source/DotNET/Tools/ProxyGenerator/Templates/Query.hbs @@ -17,25 +17,25 @@ import Handlebars from 'handlebars'; const routeTemplate = Handlebars.compile('{{{Route}}}'); -{{!-- {{#if IsEnumerable}} +{{#if IsEnumerable}} class {{Name}}SortBy { {{#Properties}} - private _{{camelCase Name}}: SortingForQuery<{{../Name}}>; + private _{{camelCase Name}}: SortingForQuery<{{../Model}}[]>; {{/Properties}} constructor(readonly query: {{Name}}) { {{#Properties}} - this._{{camelCase Name}} = new SortingForQuery({{../Name}}, query); + this._{{camelCase Name}} = new SortingForQuery<{{../Model}}[]>('{{camelCase Name}}', query); {{/Properties}} } {{#Properties}} - {{camelCase Name}}(): SortingForQuery<{{../Name}}> { + {{camelCase Name}}(): SortingForQuery<{{../Model}}[]> { return this._{{camelCase Name}}; } {{/Properties}} } -{{/if}} --}} +{{/if}} {{#if Arguments.[0]}} export interface {{Name}}Arguments { @@ -64,16 +64,16 @@ export class {{Name}} extends QueryFor<{{Model}}> { readonly routeTemplate: Handlebars.TemplateDelegate = routeTemplate; {{#if IsEnumerable}} readonly defaultValue: {{Model}}[] = []; - {{!-- readonly _sortBy: {{Name}}SortBy; --}} + readonly _sortBy: {{Name}}SortBy; {{else}} readonly defaultValue: {{Model}} = {} as any; {{/if}} constructor() { super({{Constructor}}, {{lowercase IsEnumerable}}); -{{!-- {{#if IsEnumerable}} +{{#if IsEnumerable}} this._sortBy = new {{Name}}SortBy(this); -{{/if}} --}} +{{/if}} } get requestArguments(): string[] { @@ -84,11 +84,11 @@ export class {{Name}} extends QueryFor<{{Model}}> { ]; } -{{!-- {{#if IsEnumerable}} +{{#if IsEnumerable}} get sortBy(): {{Name}}SortBy { return this._sortBy; } -{{/if}} --}} +{{/if}} {{#if Arguments.[0]}} {{#if IsEnumerable}} diff --git a/Source/JavaScript/Applications/queries/SortingForQuery.ts b/Source/JavaScript/Applications/queries/SortingForQuery.ts index 1bfe7249..a9f13304 100644 --- a/Source/JavaScript/Applications/queries/SortingForQuery.ts +++ b/Source/JavaScript/Applications/queries/SortingForQuery.ts @@ -15,7 +15,7 @@ export class SortingForQuery { * @param {string} field The field that the sorting represents. * @param {IQueryFor} query The query that holds the field. */ - constructor(readonly field: string, readonly query: IQueryFor) { + constructor(readonly field: string, readonly query: IQueryFor) { } /** From 44ae1af03acb20bea13847f1c77f18da899d2ebd Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Sat, 6 Jul 2024 08:01:25 +0200 Subject: [PATCH 02/16] Changnig addQueryParameters to addQueryParameter - singular --- Source/JavaScript/Applications/queries/QueryFor.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/JavaScript/Applications/queries/QueryFor.ts b/Source/JavaScript/Applications/queries/QueryFor.ts index d3ca6e6a..b8584cc2 100644 --- a/Source/JavaScript/Applications/queries/QueryFor.ts +++ b/Source/JavaScript/Applications/queries/QueryFor.ts @@ -64,13 +64,13 @@ export abstract class QueryFor implements IQueryFor< } if (this.paging && this.paging.pageSize > 0) { - actualRoute = this.addQueryParameters(actualRoute, 'page', this.paging.page); - actualRoute = this.addQueryParameters(actualRoute, 'pageSize', this.paging.pageSize); + actualRoute = this.addQueryParameter(actualRoute, 'page', this.paging.page); + actualRoute = this.addQueryParameter(actualRoute, 'pageSize', this.paging.pageSize); } if (this.sorting.hasSorting) { - actualRoute = this.addQueryParameters(actualRoute, 'sortBy', this.sorting.field); - actualRoute = this.addQueryParameters(actualRoute, 'sortDirection', (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc'); + actualRoute = this.addQueryParameter(actualRoute, 'sortBy', this.sorting.field); + actualRoute = this.addQueryParameter(actualRoute, 'sortDirection', (this.sorting.direction === SortDirection.descending) ? 'desc' : 'asc'); } const response = await fetch(actualRoute, { @@ -87,7 +87,7 @@ export abstract class QueryFor implements IQueryFor< } } - private addQueryParameters(route: string, key: string, value: any): string { + private addQueryParameter(route: string, key: string, value: any): string { route += (route.indexOf('?') > 0) ? '&' : '?'; route += `${key}=${value}`; return route; From d31b916de3747af153748b4f59d0fd1681045651 Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Sat, 6 Jul 2024 08:46:44 +0200 Subject: [PATCH 03/16] Set port to what the .NET port is running on --- Samples/eCommerce/Basic/Web/vite.config.mts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Samples/eCommerce/Basic/Web/vite.config.mts b/Samples/eCommerce/Basic/Web/vite.config.mts index cbd9f82f..b12ed131 100644 --- a/Samples/eCommerce/Basic/Web/vite.config.mts +++ b/Samples/eCommerce/Basic/Web/vite.config.mts @@ -24,14 +24,14 @@ export default defineConfig({ open: false, proxy: { '/api': { - target: 'http://localhost:5001', + target: 'http://localhost:5500', ws: true }, '/swagger': { - target: 'http://localhost:5001' + target: 'http://localhost:5500' }, '/.cratis': { - target: 'http://localhost:5001' + target: 'http://localhost:5500' } } }, From 15f9dbf5348a81623439808cec2f34ce93edc1d1 Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Sat, 6 Jul 2024 08:47:09 +0200 Subject: [PATCH 04/16] Making sorting work independently from paging --- .../Applications/Queries/QueryableQueryProvider.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/DotNET/Applications/Queries/QueryableQueryProvider.cs b/Source/DotNET/Applications/Queries/QueryableQueryProvider.cs index e88be274..3417f314 100644 --- a/Source/DotNET/Applications/Queries/QueryableQueryProvider.cs +++ b/Source/DotNET/Applications/Queries/QueryableQueryProvider.cs @@ -14,18 +14,17 @@ public class QueryableQueryProvider : IQueryProviderFor /// public QueryProviderResult Execute(IQueryable query, QueryContext queryContext) { - // TODO: Do you want to count here, possibly iterating the whole queryable? var totalItems = query.Count(); + + if (queryContext.Sorting != Sorting.None) + { + query = query.OrderBy(queryContext.Sorting.Field, queryContext.Sorting.Direction); + } + if (queryContext.Paging.IsPaged) { query = query.Skip(queryContext.Paging.Page * queryContext.Paging.Size) .Take(queryContext.Paging.Size); - - // TODO: Only supports sorting when paging is enabled, I think that we can support both independently. - if (queryContext.Sorting != Sorting.None) - { - query = query.OrderBy(queryContext.Sorting.Field, queryContext.Sorting.Direction); - } } return new(totalItems, query); From bffddd68a538e5f8c1b710e7ae973cadddf9041e Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Sat, 6 Jul 2024 08:47:36 +0200 Subject: [PATCH 05/16] Making sorting work independently from paging --- .../DotNET/Applications/Queries/QueryActionFilter.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/DotNET/Applications/Queries/QueryActionFilter.cs b/Source/DotNET/Applications/Queries/QueryActionFilter.cs index e4dcac26..b5426091 100644 --- a/Source/DotNET/Applications/Queries/QueryActionFilter.cs +++ b/Source/DotNET/Applications/Queries/QueryActionFilter.cs @@ -139,11 +139,13 @@ public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionE void EstablishQueryContext(ActionExecutingContext context) { var sorting = Sorting.None; + var paging = Paging.NotPaged; + if (context.HttpContext.Request.Query.ContainsKey(SortByQueryStringKey) && context.HttpContext.Request.Query.ContainsKey(SortDirectionQueryStringKey)) { sorting = new Sorting( - context.HttpContext.Request.Query[SortByQueryStringKey].ToString()!, + context.HttpContext.Request.Query[SortByQueryStringKey].ToString()!.ToPascalCase(), context.HttpContext.Request.Query[SortDirectionQueryStringKey].ToString()! == "desc" ? SortDirection.Descending : SortDirection.Ascending); } @@ -152,10 +154,10 @@ void EstablishQueryContext(ActionExecutingContext context) { var page = int.Parse(context.HttpContext.Request.Query[PageQueryStringKey].ToString()!); var pageSize = int.Parse(context.HttpContext.Request.Query[PageSizeQueryStringKey].ToString()!); - - // TODO: Now it seems like query context can only be set if paging is set, but does not support only sorting. - queryContextManager.Set(new(context.HttpContext.GetCorrelationId(), new(page, pageSize, true), sorting)); + paging = new(page, pageSize, true); } + + queryContextManager.Set(new(context.HttpContext.GetCorrelationId(), paging, sorting)); } IClientEnumerableObservable CreateClientEnumerableObservableFrom(ObjectResult objectResult) From 7cbb7e3f57e029664255a8aff05fb1adc8fc3a10 Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Sat, 6 Jul 2024 08:48:03 +0200 Subject: [PATCH 06/16] Renaming to SortingActions* and introducing actions that does not require a query instance --- .../Applications/queries/SortingActions.ts | 36 +++++++++++++++++++ ...gForQuery.ts => SortingActionsForQuery.ts} | 12 +++---- 2 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 Source/JavaScript/Applications/queries/SortingActions.ts rename Source/JavaScript/Applications/queries/{SortingForQuery.ts => SortingActionsForQuery.ts} (77%) diff --git a/Source/JavaScript/Applications/queries/SortingActions.ts b/Source/JavaScript/Applications/queries/SortingActions.ts new file mode 100644 index 00000000..d79441f0 --- /dev/null +++ b/Source/JavaScript/Applications/queries/SortingActions.ts @@ -0,0 +1,36 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +import { SortDirection } from './SortDirection'; +import { Sorting } from './Sorting'; + +/** + * Represents sorting for a query. + */ +export class SortingActions { + private readonly _ascending: Sorting; + private readonly _descending: Sorting; + + /** + * Initializes a new instance of {@link SortingActions}. + * @param {string} field The field that the sorting represents. + */ + constructor(readonly field: string) { + this._ascending = new Sorting(this.field, SortDirection.ascending); + this._descending = new Sorting(this.field, SortDirection.descending); + } + + /** + * Returns ascending sort for the field. + */ + get ascending(): Sorting { + return this._ascending; + } + + /** + * Returns ascending sort for the field. + */ + get descending(): Sorting { + return this._descending; + } +} diff --git a/Source/JavaScript/Applications/queries/SortingForQuery.ts b/Source/JavaScript/Applications/queries/SortingActionsForQuery.ts similarity index 77% rename from Source/JavaScript/Applications/queries/SortingForQuery.ts rename to Source/JavaScript/Applications/queries/SortingActionsForQuery.ts index a9f13304..a7e0d9bd 100644 --- a/Source/JavaScript/Applications/queries/SortingForQuery.ts +++ b/Source/JavaScript/Applications/queries/SortingActionsForQuery.ts @@ -8,10 +8,10 @@ import { Sorting } from './Sorting'; /** * Represents sorting for a query. */ -export class SortingForQuery { +export class SortingActionsForQuery { /** - * + * Initializes a new instance of {@link SortingActionsForQuery}. * @param {string} field The field that the sorting represents. * @param {IQueryFor} query The query that holds the field. */ @@ -21,16 +21,16 @@ export class SortingForQuery { /** * Instructs query to sort ascending for the field. */ - get ascending(): SortingForQuery { + ascending(): Sorting { this.query.sorting = new Sorting(this.field, SortDirection.ascending); - return this; + return this.query.sorting; } /** * Instructs query to sort ascending for the field. */ - get descending(): SortingForQuery { + descending(): Sorting { this.query.sorting = new Sorting(this.field, SortDirection.descending); - return this; + return this.query.sorting; } } From ba729cbfcc5b83cd9c33c4abb82a86b28036bf53 Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Sat, 6 Jul 2024 08:48:44 +0200 Subject: [PATCH 07/16] Fixing proxies to generate correct sortBy both instance and static --- .../Tools/ProxyGenerator/Templates/Query.hbs | 28 +++++++++++++++---- .../JavaScript/Applications/queries/index.ts | 3 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Source/DotNET/Tools/ProxyGenerator/Templates/Query.hbs b/Source/DotNET/Tools/ProxyGenerator/Templates/Query.hbs index bfcdd2e0..d8df8f83 100644 --- a/Source/DotNET/Tools/ProxyGenerator/Templates/Query.hbs +++ b/Source/DotNET/Tools/ProxyGenerator/Templates/Query.hbs @@ -4,7 +4,7 @@ // eslint-disable-next-line header/header {{#if IsEnumerable}} -import { QueryFor, QueryResultWithState, SortingForQuery, Paging } from '@cratis/applications/queries'; +import { QueryFor, QueryResultWithState, SortingActions, SortingActionsForQuery, Paging } from '@cratis/applications/queries'; import { useQuery, useQueryWithPaging, PerformQuery, SetSorting, SetPage } from '@cratis/applications.react/queries'; {{else}} import { QueryFor, QueryResultWithState } from '@cratis/applications/queries'; @@ -20,21 +20,34 @@ const routeTemplate = Handlebars.compile('{{{Route}}}'); {{#if IsEnumerable}} class {{Name}}SortBy { {{#Properties}} - private _{{camelCase Name}}: SortingForQuery<{{../Model}}[]>; + private _{{camelCase Name}}: SortingActionsForQuery<{{../Model}}[]>; {{/Properties}} constructor(readonly query: {{Name}}) { {{#Properties}} - this._{{camelCase Name}} = new SortingForQuery<{{../Model}}[]>('{{camelCase Name}}', query); + this._{{camelCase Name}} = new SortingActionsForQuery<{{../Model}}[]>('{{camelCase Name}}', query); {{/Properties}} } {{#Properties}} - {{camelCase Name}}(): SortingForQuery<{{../Model}}[]> { + get {{camelCase Name}}(): SortingActionsForQuery<{{../Model}}[]> { return this._{{camelCase Name}}; } {{/Properties}} } + +class {{Name}}SortByWithoutQuery { +{{#Properties}} + private _{{camelCase Name}}: SortingActions = new SortingActions('{{camelCase Name}}'); +{{/Properties}} + +{{#Properties}} + get {{camelCase Name}}(): SortingActions { + return this._{{camelCase Name}}; + } +{{/Properties}} +} + {{/if}} {{#if Arguments.[0]}} @@ -64,7 +77,8 @@ export class {{Name}} extends QueryFor<{{Model}}> { readonly routeTemplate: Handlebars.TemplateDelegate = routeTemplate; {{#if IsEnumerable}} readonly defaultValue: {{Model}}[] = []; - readonly _sortBy: {{Name}}SortBy; + private readonly _sortBy: {{Name}}SortBy; + private static readonly _sortBy: {{Name}}SortByWithoutQuery = new {{Name}}SortByWithoutQuery(); {{else}} readonly defaultValue: {{Model}} = {} as any; {{/if}} @@ -88,6 +102,10 @@ export class {{Name}} extends QueryFor<{{Model}}> { get sortBy(): {{Name}}SortBy { return this._sortBy; } + + static get sortBy(): {{Name}}SortByWithoutQuery { + return this._sortBy; + } {{/if}} {{#if Arguments.[0]}} diff --git a/Source/JavaScript/Applications/queries/index.ts b/Source/JavaScript/Applications/queries/index.ts index f9779e3e..c1095e93 100644 --- a/Source/JavaScript/Applications/queries/index.ts +++ b/Source/JavaScript/Applications/queries/index.ts @@ -5,7 +5,8 @@ export * from './IQueryFor'; export * from './Paging'; export * from './Sorting'; export * from './SortDirection'; -export * from './SortingForQuery'; +export * from './SortingActions'; +export * from './SortingActionsForQuery'; export * from './QueryFor'; export * from './QueryResult'; export * from './QueryResultWithState'; From dd0f3821d5b37d5b5f2d86ecd2681f21f4833c87 Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Sat, 6 Jul 2024 08:48:52 +0200 Subject: [PATCH 08/16] Simple sample for sorting --- .../Basic/Web/API/Products/AllProducts.ts | 44 ++++++++++++++----- Samples/eCommerce/Basic/Web/Catalog.tsx | 14 ++++++ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts b/Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts index f8b76499..12a318ff 100644 --- a/Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts +++ b/Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts @@ -3,7 +3,7 @@ *--------------------------------------------------------------------------------------------*/ // eslint-disable-next-line header/header -import { QueryFor, QueryResultWithState, SortingForQuery, Paging } from '@cratis/applications/queries'; +import { QueryFor, QueryResultWithState, SortingActions, SortingActionsForQuery, Paging } from '@cratis/applications/queries'; import { useQuery, useQueryWithPaging, PerformQuery, SetSorting, SetPage } from '@cratis/applications.react/queries'; import { Product } from './Product'; import Handlebars from 'handlebars'; @@ -11,32 +11,50 @@ import Handlebars from 'handlebars'; const routeTemplate = Handlebars.compile('/api/products/catalog'); class AllProductsSortBy { - private _id: SortingForQuery; - private _name: SortingForQuery; - private _isRegistered: SortingForQuery; + private _id: SortingActionsForQuery; + private _name: SortingActionsForQuery; + private _isRegistered: SortingActionsForQuery; constructor(readonly query: AllProducts) { - this._id = new SortingForQuery('id', query); - this._name = new SortingForQuery('name', query); - this._isRegistered = new SortingForQuery('isRegistered', query); + this._id = new SortingActionsForQuery('id', query); + this._name = new SortingActionsForQuery('name', query); + this._isRegistered = new SortingActionsForQuery('isRegistered', query); } - id(): SortingForQuery { + get id(): SortingActionsForQuery { return this._id; } - name(): SortingForQuery { + get name(): SortingActionsForQuery { return this._name; } - isRegistered(): SortingForQuery { + get isRegistered(): SortingActionsForQuery { return this._isRegistered; } } +class AllProductsSortByWithoutQuery { + private _id: SortingActions = new SortingActions('id'); + private _name: SortingActions = new SortingActions('name'); + private _isRegistered: SortingActions = new SortingActions('isRegistered'); + + get id(): SortingActions { + return this._id; + } + get name(): SortingActions { + return this._name; + } + get isRegistered(): SortingActions { + return this._isRegistered; + } +} + + export class AllProducts extends QueryFor { readonly route: string = '/api/products/catalog'; readonly routeTemplate: Handlebars.TemplateDelegate = routeTemplate; readonly defaultValue: Product[] = []; - readonly _sortBy: AllProductsSortBy; + private readonly _sortBy: AllProductsSortBy; + private static readonly _sortBy: AllProductsSortByWithoutQuery = new AllProductsSortByWithoutQuery(); constructor() { super(Product, true); @@ -52,6 +70,10 @@ export class AllProducts extends QueryFor { return this._sortBy; } + static get sortBy(): AllProductsSortByWithoutQuery { + return this._sortBy; + } + static use(): [QueryResultWithState, PerformQuery, SetSorting] { return useQuery(AllProducts); } diff --git a/Samples/eCommerce/Basic/Web/Catalog.tsx b/Samples/eCommerce/Basic/Web/Catalog.tsx index b758e6cf..59d92dc1 100644 --- a/Samples/eCommerce/Basic/Web/Catalog.tsx +++ b/Samples/eCommerce/Basic/Web/Catalog.tsx @@ -10,6 +10,7 @@ import { useState } from 'react'; export const Catalog = withViewModel(CatalogViewModel, ({ viewModel }) => { const [products, currentPage, perform, setSorting, setPage] = AllProducts.useWithPaging(10); + const [descending, setDescending] = useState(false); return (
@@ -23,6 +24,19 @@ export const Catalog = withViewModel(CatalogViewModel, ({ viewModel }) => { const page = currentPage + 1; setPage(page); }}>Next page +
+ +
); }); From e88fb389ecbcf4eef49e48da15c6e1df91c88366 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 18 Jul 2024 10:40:45 +0300 Subject: [PATCH 09/16] MobxOptions prop optional --- .../Applications.React.MVVM/MVVMContext.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx b/Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx index 587798ea..bf007cdd 100644 --- a/Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx +++ b/Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx @@ -8,22 +8,20 @@ import { MobxOptions } from './MobxOptions'; export interface MVVMProps { children?: JSX.Element | JSX.Element[]; - mobx: MobxOptions | undefined + mobx?: MobxOptions; } export const MVVMContext = React.createContext({}); export const MVVM = (props: MVVMProps) => { - - const options: MobxOptions = { ...{ enforceActions: 'never' }, ...props.mobx || {} }; - + const options: MobxOptions = { + ...{ enforceActions: 'never' }, + ...(props.mobx || {}), + }; + debugger; configureMobx(options); Bindings.initialize(); - return ( - - {props.children} - - ); -}; \ No newline at end of file + return {props.children}; +}; From 4075f41ab2e3066605cc60efc819db110da62bf3 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 18 Jul 2024 10:59:47 +0300 Subject: [PATCH 10/16] Remove debugger --- Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx b/Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx index bf007cdd..992c3036 100644 --- a/Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx +++ b/Source/JavaScript/Applications.React.MVVM/MVVMContext.tsx @@ -18,7 +18,7 @@ export const MVVM = (props: MVVMProps) => { ...{ enforceActions: 'never' }, ...(props.mobx || {}), }; - debugger; + configureMobx(options); Bindings.initialize(); From a2344cf2ed6f4eee041deae043b253f939460ed5 Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Thu, 18 Jul 2024 10:11:05 +0200 Subject: [PATCH 11/16] Adding write access to contents --- .github/workflows/publish.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3a1a5763..b63376f6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,6 +33,9 @@ on: paths: - "**" +permissions: + contents: write + jobs: release: runs-on: ubuntu-latest From 2fb7cd2b00cfeb137c942e7c029b48b2742190ae Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Thu, 18 Jul 2024 10:13:21 +0200 Subject: [PATCH 12/16] Adding missing Header --- Source/DotNET/Swagger/ConceptSchemaFilter.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/DotNET/Swagger/ConceptSchemaFilter.cs b/Source/DotNET/Swagger/ConceptSchemaFilter.cs index c6e7df68..a2e24704 100644 --- a/Source/DotNET/Swagger/ConceptSchemaFilter.cs +++ b/Source/DotNET/Swagger/ConceptSchemaFilter.cs @@ -1,3 +1,6 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using Cratis.Concepts; using Microsoft.OpenApi.Extensions; using Microsoft.OpenApi.Models; From 19083791f9773813254f3f9b2b70ef7d5df64f35 Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Thu, 18 Jul 2024 10:13:48 +0200 Subject: [PATCH 13/16] Adding non generic BaseClass for CommandResult without response --- .../Applications/Commands/CommandResult.cs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Source/DotNET/Applications/Commands/CommandResult.cs b/Source/DotNET/Applications/Commands/CommandResult.cs index 1349de1f..7c40475b 100644 --- a/Source/DotNET/Applications/Commands/CommandResult.cs +++ b/Source/DotNET/Applications/Commands/CommandResult.cs @@ -6,17 +6,13 @@ namespace Cratis.Applications.Commands; +#pragma warning disable SA1402 // File may only contain a single type + /// /// Represents the result coming from executing a command. /// -/// Type of the data returned. -public class CommandResult +public class CommandResult { - /// - /// Represents a successful command result. - /// - public static readonly CommandResult Success = new(); - /// /// Gets the associated with the command. /// @@ -56,6 +52,18 @@ public class CommandResult /// Gets the stack trace if there was an exception. /// public string ExceptionStackTrace { get; init; } = string.Empty; +} + +/// +/// Represents the result coming from executing a command with a response. +/// +/// Type of the data returned. +public class CommandResult : CommandResult +{ + /// + /// Represents a successful command result. + /// + public static readonly CommandResult Success = new(); /// /// Optional response object. Controller actions representing a command can optionally return a response as any type, this is where it would be. From 9ed16192076687ce31494f343f68f3a8c81ac24c Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Thu, 18 Jul 2024 10:14:05 +0200 Subject: [PATCH 14/16] Implemented OperationFilter for Swagger definition for supporting CommandResult --- Directory.Packages.props | 2 +- .../Commands/CommandMethodExtensions.cs | 24 +++++++++ .../Swagger/CommandResultOperationFilter.cs | 50 +++++++++++++++++++ Source/DotNET/Swagger/Extensions.cs | 11 +++- Source/DotNET/Swagger/Swagger.csproj | 4 ++ 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 Source/DotNET/Applications/Commands/CommandMethodExtensions.cs create mode 100644 Source/DotNET/Swagger/CommandResultOperationFilter.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index b2177301..d35d762a 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,7 +3,7 @@ true - + diff --git a/Source/DotNET/Applications/Commands/CommandMethodExtensions.cs b/Source/DotNET/Applications/Commands/CommandMethodExtensions.cs new file mode 100644 index 00000000..542ac165 --- /dev/null +++ b/Source/DotNET/Applications/Commands/CommandMethodExtensions.cs @@ -0,0 +1,24 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Reflection; +using Cratis.Reflection; +using Microsoft.AspNetCore.Mvc; + +namespace Cratis.Applications.Commands; + +/// +/// Extension methods for methods representing commands. +/// +public static class CommandMethodExtensions +{ + /// + /// Check if a method is a command. + /// + /// The to check. + /// True if it is a command, false if not. + public static bool IsCommand(this MethodInfo methodInfo) => + methodInfo.HasAttribute() && + !methodInfo.HasAttribute() && + (!methodInfo.DeclaringType?.HasAttribute() ?? false); +} \ No newline at end of file diff --git a/Source/DotNET/Swagger/CommandResultOperationFilter.cs b/Source/DotNET/Swagger/CommandResultOperationFilter.cs new file mode 100644 index 00000000..c8d5335a --- /dev/null +++ b/Source/DotNET/Swagger/CommandResultOperationFilter.cs @@ -0,0 +1,50 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Cratis.Applications.Commands; +using Cratis.Concepts; +using Cratis.Reflection; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace Cratis.Applications.Swagger; + +/// +/// Represents an implementation of that adds the command result to the operation for command methods. +/// +/// The to use. +public class CommandResultOperationFilter(ISchemaGenerator schemaGenerator) : IOperationFilter +{ + /// + public void Apply(OpenApiOperation operation, OperationFilterContext context) + { + if (!context.MethodInfo.IsCommand()) return; + + var returnType = context.MethodInfo.GetActualReturnType(); + + Type? commandResultType = null; + + if (returnType == typeof(Task) || returnType == typeof(ValueTask) || returnType == typeof(void)) + { + returnType = typeof(object); + commandResultType = typeof(CommandResult); + } + else if (returnType.IsConcept()) + { + returnType = returnType.GetConceptValueType(); + } + + commandResultType ??= typeof(CommandResult<>).MakeGenericType(returnType); + + var schema = schemaGenerator.GenerateSchema(commandResultType, context.SchemaRepository); + var response = operation.Responses.First().Value; + if (response.Content.ContainsKey("application/json")) + { + operation.Responses.First().Value.Content["application/json"].Schema = schema; + } + else + { + response.Content.Add(new("application/json", new() { Schema = schema })); + } + } +} diff --git a/Source/DotNET/Swagger/Extensions.cs b/Source/DotNET/Swagger/Extensions.cs index dd583ba8..410896f1 100644 --- a/Source/DotNET/Swagger/Extensions.cs +++ b/Source/DotNET/Swagger/Extensions.cs @@ -1,3 +1,6 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + using Microsoft.Extensions.DependencyInjection; using Swashbuckle.AspNetCore.SwaggerGen; @@ -12,5 +15,9 @@ public static class Extensions /// Adds the . /// /// The . - public static void AddConcepts(this SwaggerGenOptions options) => options.SchemaFilter(); -} \ No newline at end of file + public static void AddConcepts(this SwaggerGenOptions options) + { + options.SchemaFilter(); + options.OperationFilter(); + } +} diff --git a/Source/DotNET/Swagger/Swagger.csproj b/Source/DotNET/Swagger/Swagger.csproj index bf6526f7..0fad56b3 100644 --- a/Source/DotNET/Swagger/Swagger.csproj +++ b/Source/DotNET/Swagger/Swagger.csproj @@ -7,4 +7,8 @@ + + + + From 9f4458342d388764b90e9d0c62b7ea76276401bb Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Thu, 18 Jul 2024 10:27:12 +0200 Subject: [PATCH 15/16] Adding support for QueryResult in Swagger --- .../Queries/QueryMethodExtensions.cs | 27 ++++++++++++ Source/DotNET/Swagger/Extensions.cs | 1 + .../Swagger/QueryResultOperationFilter.cs | 43 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 Source/DotNET/Applications/Queries/QueryMethodExtensions.cs create mode 100644 Source/DotNET/Swagger/QueryResultOperationFilter.cs diff --git a/Source/DotNET/Applications/Queries/QueryMethodExtensions.cs b/Source/DotNET/Applications/Queries/QueryMethodExtensions.cs new file mode 100644 index 00000000..932acad5 --- /dev/null +++ b/Source/DotNET/Applications/Queries/QueryMethodExtensions.cs @@ -0,0 +1,27 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Reflection; +using Cratis.Reflection; +using Microsoft.AspNetCore.Mvc; + +namespace Cratis.Applications.Queries; + +/// +/// Extension methods for methods representing commands. +/// +public static class QueryMethodExtensions +{ + /// + /// Check if a method is a command. + /// + /// The to check. + /// True if it is a command, false if not. + public static bool IsQuery(this MethodInfo methodInfo) => + methodInfo.HasAttribute() && + methodInfo.ReturnType != typeof(void) && + methodInfo.ReturnType != typeof(Task) && + methodInfo.ReturnType != typeof(ValueTask) && + !methodInfo.HasAttribute() && + (!methodInfo.DeclaringType?.HasAttribute() ?? false); +} \ No newline at end of file diff --git a/Source/DotNET/Swagger/Extensions.cs b/Source/DotNET/Swagger/Extensions.cs index 410896f1..4242da2d 100644 --- a/Source/DotNET/Swagger/Extensions.cs +++ b/Source/DotNET/Swagger/Extensions.cs @@ -19,5 +19,6 @@ public static void AddConcepts(this SwaggerGenOptions options) { options.SchemaFilter(); options.OperationFilter(); + options.OperationFilter(); } } diff --git a/Source/DotNET/Swagger/QueryResultOperationFilter.cs b/Source/DotNET/Swagger/QueryResultOperationFilter.cs new file mode 100644 index 00000000..f35dc0d4 --- /dev/null +++ b/Source/DotNET/Swagger/QueryResultOperationFilter.cs @@ -0,0 +1,43 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Cratis.Applications.Queries; +using Cratis.Concepts; +using Cratis.Reflection; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; + +namespace Cratis.Applications.Swagger; + +/// +/// Represents an implementation of that adds the command result to the operation for command methods. +/// +/// The to use. +public class QueryResultOperationFilter(ISchemaGenerator schemaGenerator) : IOperationFilter +{ + /// + public void Apply(OpenApiOperation operation, OperationFilterContext context) + { + if (!context.MethodInfo.IsQuery()) return; + + var returnType = context.MethodInfo.GetActualReturnType(); + + if (returnType.IsConcept()) + { + returnType = returnType.GetConceptValueType(); + } + + var queryResultType = typeof(QueryResult<>).MakeGenericType(returnType); + + var schema = schemaGenerator.GenerateSchema(queryResultType, context.SchemaRepository); + var response = operation.Responses.First().Value; + if (response.Content.ContainsKey("application/json")) + { + operation.Responses.First().Value.Content["application/json"].Schema = schema; + } + else + { + response.Content.Add(new("application/json", new() { Schema = schema })); + } + } +} From d5f5c1d7b24e2f4d00e4d04dae49a325830ef9bf Mon Sep 17 00:00:00 2001 From: Einar Ingebrigtsen Date: Thu, 18 Jul 2024 13:23:56 +0200 Subject: [PATCH 16/16] Movinc Spec projects next to the actual projects they're specifying; high cohesion --- .editorconfig | 74 +++++++++++++++ ApplicationModel.sln | 11 +-- Directory.Packages.props | 1 + .../eCommerce/Basic/API/Products/Catalog.cs | 2 + .../eCommerce/Basic/API/Products/Inventory.cs | 4 +- Samples/eCommerce/Basic/Web/Feature.tsx | 1 - .../Applications.Specs.csproj | 2 +- .../given/a_valid_identity_request.cs | 0 .../given/an_identity_provider_endpoint.cs | 0 .../when_handling/and_claims_are_missing.cs | 0 .../and_identity_id_header_is_missing.cs | 0 ...d_identity_is_valid_with_multiple_roles.cs | 0 .../and_identity_name_header_is_missing.cs | 0 .../and_principal_header_is_missing.cs | 0 .../and_there_are_multiple_providers.cs | 0 .../and_there_are_no_providers.cs | 0 .../and_there_is_one_provider.cs | 0 .../for_FromRequestModelBinder/TheModel.cs | 0 ...l_is_provided_partially_by_both_binders.cs | 0 .../for_QueryableExtensions/when_counting.cs | 0 .../when_ordering_ascending.cs | 0 .../when_ordering_descending.cs | 0 .../for_QueryableExtensions/when_skipping.cs | 0 .../for_QueryableExtensions/when_taking.cs | 0 .../when_converting_nested_member.cs | 0 ...hen_converting_nested_member_with_array.cs | 0 .../when_converting_simple_member.cs | 0 Source/DotNET/Applications/Assembly.cs | 6 ++ Source/DotNET/Applications/Internals.cs | 33 ++++++- .../ServiceProviderNotConfigured.cs | 17 ++++ .../TypeDiscoverySystemNotConfigured.cs | 17 ++++ .../ValidationMvcOptionsExtensions.cs | 2 +- Source/DotNET/Directory.Build.props | 10 ++ .../DotNET/GlobalUsings.Specs.cs | 2 + .../DotNET/MongoDB.Specs/MongoDB.Specs.csproj | 3 +- .../InvocationTarget.cs | 0 .../given/an_interceptor.cs | 0 .../when_intercepting/cancelled_method.cs | 0 .../when_intercepting/faulted_method.cs | 0 .../faulted_method_without_task.cs | 0 .../when_intercepting/successful_method.cs | 0 .../InvocationTarget.cs | 0 .../given/an_interceptor.cs | 0 .../when_intercepting/cancelled_method.cs | 0 .../when_intercepting/faulted_method.cs | 0 .../faulted_method_without_task.cs | 0 .../when_intercepting/successful_method.cs | 0 .../given/an_interceptor_selector.cs | 0 .../for_async_methods.cs | 0 .../for_async_methods_with_return_value.cs | 0 .../for_sync_methods.cs | 0 ...ing_convention_to_all_class_map_members.cs | 0 .../when_applying_conventions.cs | 0 ...mbers_one_wants_to_keep_are_camel_cased.cs | 0 ...n_specified_in_ignore_attribute_on_type.cs | 0 ...s_specified_in_ignore_attribute_on_type.cs | 0 ...type_with_ignore_attribute_ignoring_all.cs | 0 ...clude_for_type_without_ignore_attribute.cs | 0 Source/DotNET/MongoDB/MongoDB.csproj | 9 +- .../MongoDB/MongoDBCollectionExtensions.cs | 95 ++++++++++--------- .../DotNET/Orleans.Specs/Orleans.Specs.csproj | 3 +- .../Orleans.Specs}/StateMachines/BaseState.cs | 0 .../StateMachines/StateMachineForTesting.cs | 0 .../StateMachineStateForTesting.cs | 0 ...tateThatDoesNotSupportTransitioningFrom.cs | 0 .../StateThatSupportsTransitioningFrom.cs | 0 .../StateThatTransitionsOnEnter.cs | 0 .../StateThatTransitionsOnLeave.cs | 0 .../StateWithAllowedTransitionState.cs | 0 .../StateWithoutAllowedTransitionState.cs | 0 .../StateMachines/UnknownState.cs | 0 .../and_it_does_not_have_state_as_allowed.cs | 0 .../and_it_has_state_as_allowed.cs | 0 .../for_StateMachine/given/a_state_machine.cs | 0 .../a_state_machine_with_well_known_states.cs | 0 .../with_invalid_initial_state_type.cs | 0 .../with_known_current_state.cs | 0 .../with_known_initial_state_type.cs | 0 .../with_unknown_current_state.cs | 0 .../with_unknown_initial_state_type.cs | 0 .../with_valid_initial_state_type.cs | 0 .../and_state_allows_it.cs | 0 .../and_state_does_not_allow_it.cs | 0 .../and_it_is.cs | 0 .../and_it_is_not.cs | 0 .../when_deactivating_grain.cs | 0 .../and_state_can_be_transitioned_to.cs | 0 .../and_state_is_unknown_state_type.cs | 0 ...nsitions_to_other_state_during_on_enter.cs | 0 ...nsitions_to_other_state_during_on_leave.cs | 0 Specifications/Directory.Build.props | 29 ------ Specifications/WarningsToIgnore.props | 69 -------------- 92 files changed, 230 insertions(+), 160 deletions(-) rename Specifications/Applications/Applications.csproj => Source/DotNET/Applications.Specs/Applications.Specs.csproj (81%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpoint/given/a_valid_identity_request.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpoint/given/an_identity_provider_endpoint.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpoint/when_handling/and_claims_are_missing.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_id_header_is_missing.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_is_valid_with_multiple_roles.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_name_header_is_missing.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpoint/when_handling/and_principal_header_is_missing.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_multiple_providers.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_no_providers.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_is_one_provider.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/ModelBinding/for_FromRequestModelBinder/TheModel.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/ModelBinding/for_FromRequestModelBinder/when_model_is_provided_partially_by_both_binders.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Queries/for_QueryableExtensions/when_counting.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Queries/for_QueryableExtensions/when_ordering_ascending.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Queries/for_QueryableExtensions/when_ordering_descending.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Queries/for_QueryableExtensions/when_skipping.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Queries/for_QueryableExtensions/when_taking.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Validation/for_ModelErrorExtensions/when_converting_nested_member.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Validation/for_ModelErrorExtensions/when_converting_nested_member_with_array.cs (100%) rename {Specifications/Applications => Source/DotNET/Applications.Specs}/Validation/for_ModelErrorExtensions/when_converting_simple_member.cs (100%) create mode 100644 Source/DotNET/Applications/Assembly.cs create mode 100644 Source/DotNET/Applications/ServiceProviderNotConfigured.cs create mode 100644 Source/DotNET/Applications/TypeDiscoverySystemNotConfigured.cs rename Specifications/GlobalUsings.cs => Source/DotNET/GlobalUsings.Specs.cs (81%) rename Specifications/MongoDB/MongoDB.csproj => Source/DotNET/MongoDB.Specs/MongoDB.Specs.csproj (70%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptor/InvocationTarget.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptor/given/an_interceptor.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptor/when_intercepting/cancelled_method.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method_without_task.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptor/when_intercepting/successful_method.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorForReturnValue/InvocationTarget.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorForReturnValue/given/an_interceptor.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/cancelled_method.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method_without_task.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/successful_method.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorSelector/given/an_interceptor_selector.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods_with_return_value.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_sync_methods.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/for_AcronymFriendlyCamelCaseElementNameConvention/when_applying_convention_to_all_class_map_members.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/for_BsonClassMapExtensions/when_applying_conventions.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/for_BsonClassMapExtensions/when_unmapping_all_except/and_members_one_wants_to_keep_are_camel_cased.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_pack_other_than_specified_in_ignore_attribute_on_type.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_same_as_specified_in_ignore_attribute_on_type.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_with_ignore_attribute_ignoring_all.cs (100%) rename {Specifications/MongoDB => Source/DotNET/MongoDB.Specs}/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_without_ignore_attribute.cs (100%) rename Specifications/Orleans/Orleans.csproj => Source/DotNET/Orleans.Specs/Orleans.Specs.csproj (78%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/BaseState.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/StateMachineForTesting.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/StateMachineStateForTesting.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/StateThatDoesNotSupportTransitioningFrom.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/StateThatSupportsTransitioningFrom.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/StateThatTransitionsOnEnter.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/StateThatTransitionsOnLeave.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/StateWithAllowedTransitionState.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/StateWithoutAllowedTransitionState.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/UnknownState.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_State/when_asking_can_transition/and_it_does_not_have_state_as_allowed.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_State/when_asking_can_transition/and_it_has_state_as_allowed.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/given/a_state_machine.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/given/a_state_machine_with_well_known_states.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_activating/with_invalid_initial_state_type.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_activating/with_known_current_state.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_activating/with_known_initial_state_type.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_activating/with_unknown_current_state.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_activating/with_unknown_initial_state_type.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_activating/with_valid_initial_state_type.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_allows_it.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_does_not_allow_it.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is_not.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_deactivating_grain.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_transitioning/and_state_can_be_transitioned_to.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_transitioning/and_state_is_unknown_state_type.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_enter.cs (100%) rename {Specifications/Orleans => Source/DotNET/Orleans.Specs}/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_leave.cs (100%) delete mode 100644 Specifications/Directory.Build.props delete mode 100644 Specifications/WarningsToIgnore.props diff --git a/.editorconfig b/.editorconfig index 5af865bd..7092e323 100644 --- a/.editorconfig +++ b/.editorconfig @@ -118,3 +118,77 @@ csharp_style_prefer_range_operator = false:none dotnet_diagnostic.IDE0055.severity = none # prefere brace indentation when creating objects etc csharp_indent_braces = false + +[**/*.Specs/**/*.cs] +# Resharper specific +resharper_inconsistent_naming_highlighting = none +resharper_check_namespace_highlighting = none +resharper_unused_member_local_highlighting = none +dotnet_diagnostic.CA1001.severity = none +dotnet_diagnostic.CA1008.severity = none +dotnet_diagnostic.CA1024.severity = none +dotnet_diagnostic.CA1034.severity = none +dotnet_diagnostic.CA1051.severity = none +dotnet_diagnostic.CA1305.severity = none +dotnet_diagnostic.CA1707.severity = none +dotnet_diagnostic.CA1813.severity = none +dotnet_diagnostic.CA1852.severity = none +dotnet_diagnostic.CA1861.severity = none +dotnet_diagnostic.CA2000.severity = none +dotnet_diagnostic.CA2201.severity = none +dotnet_diagnostic.CA2211.severity = none +dotnet_diagnostic.CA2252.severity = none +dotnet_diagnostic.CS8600.severity = none +dotnet_diagnostic.CS8601.severity = none +dotnet_diagnostic.CS8602.severity = none +dotnet_diagnostic.CS8604.severity = none +dotnet_diagnostic.CS8632.severity = none +dotnet_diagnostic.CS8618.severity = none +dotnet_diagnostic.CS8765.severity = none +dotnet_diagnostic.CS8981.severity = none +dotnet_diagnostic.CS9113.severity = none +dotnet_diagnostic.IDE0005.severity = none +dotnet_diagnostic.IDE0044.severity = none +dotnet_diagnostic.IDE0051.severity = none +dotnet_diagnostic.IDE0052.severity = none +dotnet_diagnostic.IDE0060.severity = none +dotnet_diagnostic.IDE1006.severity = none +dotnet_diagnostic.SA0001.severity = none +dotnet_diagnostic.SA1116.severity = none +dotnet_diagnostic.SA1122.severity = none +dotnet_diagnostic.SA1134.severity = none +dotnet_diagnostic.SA1201.severity = none +dotnet_diagnostic.SA1202.severity = none +dotnet_diagnostic.SA1203.severity = none +dotnet_diagnostic.SA1204.severity = none +dotnet_diagnostic.SA1214.severity = none +dotnet_diagnostic.SA1303.severity = none +dotnet_diagnostic.SA1304.severity = none +dotnet_diagnostic.SA1306.severity = none +dotnet_diagnostic.SA1307.severity = none +dotnet_diagnostic.SA1311.severity = none +dotnet_diagnostic.SA1312.severity = none +dotnet_diagnostic.SA1313.severity = none +dotnet_diagnostic.SA1402.severity = none +dotnet_diagnostic.SA1500.severity = none +dotnet_diagnostic.SA1502.severity = none +dotnet_diagnostic.SA1507.severity = none +dotnet_diagnostic.SA1600.severity = none +dotnet_diagnostic.RCS1018.severity = none +dotnet_diagnostic.RCS1036.severity = none +dotnet_diagnostic.RCS1090.severity = none +dotnet_diagnostic.RCS1163.severity = none +dotnet_diagnostic.RCS1169.severity = none +dotnet_diagnostic.RCS1202.severity = none +dotnet_diagnostic.RCS1213.severity = none +dotnet_diagnostic.RCS1225.severity = none +dotnet_diagnostic.RCS1241.severity = none +dotnet_diagnostic.MA0016.severity = none +dotnet_diagnostic.MA0036.severity = none +dotnet_diagnostic.MA0041.severity = none +dotnet_diagnostic.MA0044.severity = none +dotnet_diagnostic.MA0048.severity = none +dotnet_diagnostic.MA0069.severity = none +dotnet_diagnostic.MA0096.severity = none +dotnet_diagnostic.MA0097.severity = none +dotnet_diagnostic.MA0132.severity = none diff --git a/ApplicationModel.sln b/ApplicationModel.sln index bf752d8d..1aec796e 100644 --- a/ApplicationModel.sln +++ b/ApplicationModel.sln @@ -9,9 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNET", "DotNET", "{856932 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications", "Source\DotNET\Applications\Applications.csproj", "{AA6A18EA-D0F5-41C7-AF7D-1BD124022C71}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Specifications", "Specifications", "{597AD628-3D8C-411C-899D-7A03AF4E6E2B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications", "Specifications\Applications\Applications.csproj", "{B692D48E-BD85-4F12-ADE3-15F3D3A1F710}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications.Specs", "Source\DotNET\Applications.Specs\Applications.Specs.csproj", "{B692D48E-BD85-4F12-ADE3-15F3D3A1F710}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog", "Source\DotNET\Serilog\Serilog.csproj", "{B2BF4443-5421-4275-A6A4-83C3E1C140B5}" EndProject @@ -27,9 +25,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxyGenerator", "Source\Do EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans", "Source\DotNET\Orleans\Orleans.csproj", "{972CE865-9F7F-45D7-900C-5D81151D8105}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans", "Specifications\Orleans\Orleans.csproj", "{5F687FC5-0763-470E-AF27-4C2E8C8DCCFD}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans.Specs", "Source\DotNET\Orleans.Specs\Orleans.Specs.csproj", "{5F687FC5-0763-470E-AF27-4C2E8C8DCCFD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB", "Specifications\MongoDB\MongoDB.csproj", "{A9723526-B6DA-40E6-A80A-5F566892DF45}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Specs", "Source\DotNET\MongoDB.Specs\MongoDB.Specs.csproj", "{A9723526-B6DA-40E6-A80A-5F566892DF45}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB", "Source\DotNET\MongoDB\MongoDB.csproj", "{55CA3EF1-6CF9-4226-A3C3-89B0A654A268}" EndProject @@ -132,14 +130,11 @@ Global GlobalSection(NestedProjects) = preSolution {856932F6-D1D1-41CC-808B-A3741518DACC} = {CB36289F-614E-4733-B81A-74AC5658E5CB} {AA6A18EA-D0F5-41C7-AF7D-1BD124022C71} = {856932F6-D1D1-41CC-808B-A3741518DACC} - {B692D48E-BD85-4F12-ADE3-15F3D3A1F710} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B} {B2BF4443-5421-4275-A6A4-83C3E1C140B5} = {856932F6-D1D1-41CC-808B-A3741518DACC} {FC67C7C1-EBC1-430E-9229-BF694CC67820} = {CB36289F-614E-4733-B81A-74AC5658E5CB} {A495F734-D1D2-453B-97BA-90FD1F95A66B} = {856932F6-D1D1-41CC-808B-A3741518DACC} {D25312B1-B1F7-44EA-8FBF-1910DEC9C1FA} = {A495F734-D1D2-453B-97BA-90FD1F95A66B} {972CE865-9F7F-45D7-900C-5D81151D8105} = {856932F6-D1D1-41CC-808B-A3741518DACC} - {5F687FC5-0763-470E-AF27-4C2E8C8DCCFD} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B} - {A9723526-B6DA-40E6-A80A-5F566892DF45} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B} {55CA3EF1-6CF9-4226-A3C3-89B0A654A268} = {856932F6-D1D1-41CC-808B-A3741518DACC} {BE230ADD-9372-479D-9912-CB1AF36ADD0A} = {A495F734-D1D2-453B-97BA-90FD1F95A66B} {A699BADC-5E16-4AA0-B275-3FF5B9F6BA38} = {856932F6-D1D1-41CC-808B-A3741518DACC} diff --git a/Directory.Packages.props b/Directory.Packages.props index d35d762a..f8fb46b3 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -52,5 +52,6 @@ + \ No newline at end of file diff --git a/Samples/eCommerce/Basic/API/Products/Catalog.cs b/Samples/eCommerce/Basic/API/Products/Catalog.cs index 4bd680ca..5eb9972f 100644 --- a/Samples/eCommerce/Basic/API/Products/Catalog.cs +++ b/Samples/eCommerce/Basic/API/Products/Catalog.cs @@ -12,6 +12,8 @@ namespace API.Products; /// Represents the catalog API. /// /// for working with grains. +/// for working with the catalog. +/// for working with products. [Route("/api/products/catalog")] public class Catalog(IGrainFactory grainFactory, ICatalogQueries catalogQueries, IMongoCollection collection) : ControllerBase { diff --git a/Samples/eCommerce/Basic/API/Products/Inventory.cs b/Samples/eCommerce/Basic/API/Products/Inventory.cs index 3b52b7e4..1c3e1841 100644 --- a/Samples/eCommerce/Basic/API/Products/Inventory.cs +++ b/Samples/eCommerce/Basic/API/Products/Inventory.cs @@ -17,7 +17,9 @@ public class Inventory : ControllerBase /// The command payload. /// Awaitable task. [HttpPost("set-stock/{sku}")] - public Task SetStockForProduct([FromRoute] SKU sku, [FromBody] SetStockForProduct command) + public Task SetStockForProduct( + [FromRoute] SKU sku, + [FromBody] SetStockForProduct command) { Console.WriteLine($"Setting stock for product {sku} to {command.Quantity}"); return Task.CompletedTask; diff --git a/Samples/eCommerce/Basic/Web/Feature.tsx b/Samples/eCommerce/Basic/Web/Feature.tsx index 43fc636c..4f822484 100644 --- a/Samples/eCommerce/Basic/Web/Feature.tsx +++ b/Samples/eCommerce/Basic/Web/Feature.tsx @@ -10,7 +10,6 @@ import { useIdentity } from '@cratis/applications.react/identity'; export const Feature = withViewModel(FeatureViewModel, ({ viewModel }) => { const identity = useIdentity(); - return (

Hello {`${identity.name}`} your cart id is {`${viewModel.cart.id}`}

diff --git a/Specifications/Applications/Applications.csproj b/Source/DotNET/Applications.Specs/Applications.Specs.csproj similarity index 81% rename from Specifications/Applications/Applications.csproj rename to Source/DotNET/Applications.Specs/Applications.Specs.csproj index 67c9a1f3..770c2cf5 100644 --- a/Specifications/Applications/Applications.csproj +++ b/Source/DotNET/Applications.Specs/Applications.Specs.csproj @@ -6,7 +6,7 @@ - + diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpoint/given/a_valid_identity_request.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/given/a_valid_identity_request.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpoint/given/a_valid_identity_request.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/given/a_valid_identity_request.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpoint/given/an_identity_provider_endpoint.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/given/an_identity_provider_endpoint.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpoint/given/an_identity_provider_endpoint.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/given/an_identity_provider_endpoint.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_claims_are_missing.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_claims_are_missing.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_claims_are_missing.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_claims_are_missing.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_id_header_is_missing.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_id_header_is_missing.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_id_header_is_missing.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_id_header_is_missing.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_is_valid_with_multiple_roles.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_is_valid_with_multiple_roles.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_is_valid_with_multiple_roles.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_is_valid_with_multiple_roles.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_name_header_is_missing.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_name_header_is_missing.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_name_header_is_missing.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_identity_name_header_is_missing.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_principal_header_is_missing.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_principal_header_is_missing.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpoint/when_handling/and_principal_header_is_missing.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpoint/when_handling/and_principal_header_is_missing.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_multiple_providers.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_multiple_providers.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_multiple_providers.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_multiple_providers.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_no_providers.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_no_providers.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_no_providers.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_are_no_providers.cs diff --git a/Specifications/Applications/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_is_one_provider.cs b/Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_is_one_provider.cs similarity index 100% rename from Specifications/Applications/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_is_one_provider.cs rename to Source/DotNET/Applications.Specs/Identity/for_IdentityProviderEndpointExtensions/when_adding_identity_provider/and_there_is_one_provider.cs diff --git a/Specifications/Applications/ModelBinding/for_FromRequestModelBinder/TheModel.cs b/Source/DotNET/Applications.Specs/ModelBinding/for_FromRequestModelBinder/TheModel.cs similarity index 100% rename from Specifications/Applications/ModelBinding/for_FromRequestModelBinder/TheModel.cs rename to Source/DotNET/Applications.Specs/ModelBinding/for_FromRequestModelBinder/TheModel.cs diff --git a/Specifications/Applications/ModelBinding/for_FromRequestModelBinder/when_model_is_provided_partially_by_both_binders.cs b/Source/DotNET/Applications.Specs/ModelBinding/for_FromRequestModelBinder/when_model_is_provided_partially_by_both_binders.cs similarity index 100% rename from Specifications/Applications/ModelBinding/for_FromRequestModelBinder/when_model_is_provided_partially_by_both_binders.cs rename to Source/DotNET/Applications.Specs/ModelBinding/for_FromRequestModelBinder/when_model_is_provided_partially_by_both_binders.cs diff --git a/Specifications/Applications/Queries/for_QueryableExtensions/when_counting.cs b/Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_counting.cs similarity index 100% rename from Specifications/Applications/Queries/for_QueryableExtensions/when_counting.cs rename to Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_counting.cs diff --git a/Specifications/Applications/Queries/for_QueryableExtensions/when_ordering_ascending.cs b/Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_ordering_ascending.cs similarity index 100% rename from Specifications/Applications/Queries/for_QueryableExtensions/when_ordering_ascending.cs rename to Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_ordering_ascending.cs diff --git a/Specifications/Applications/Queries/for_QueryableExtensions/when_ordering_descending.cs b/Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_ordering_descending.cs similarity index 100% rename from Specifications/Applications/Queries/for_QueryableExtensions/when_ordering_descending.cs rename to Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_ordering_descending.cs diff --git a/Specifications/Applications/Queries/for_QueryableExtensions/when_skipping.cs b/Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_skipping.cs similarity index 100% rename from Specifications/Applications/Queries/for_QueryableExtensions/when_skipping.cs rename to Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_skipping.cs diff --git a/Specifications/Applications/Queries/for_QueryableExtensions/when_taking.cs b/Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_taking.cs similarity index 100% rename from Specifications/Applications/Queries/for_QueryableExtensions/when_taking.cs rename to Source/DotNET/Applications.Specs/Queries/for_QueryableExtensions/when_taking.cs diff --git a/Specifications/Applications/Validation/for_ModelErrorExtensions/when_converting_nested_member.cs b/Source/DotNET/Applications.Specs/Validation/for_ModelErrorExtensions/when_converting_nested_member.cs similarity index 100% rename from Specifications/Applications/Validation/for_ModelErrorExtensions/when_converting_nested_member.cs rename to Source/DotNET/Applications.Specs/Validation/for_ModelErrorExtensions/when_converting_nested_member.cs diff --git a/Specifications/Applications/Validation/for_ModelErrorExtensions/when_converting_nested_member_with_array.cs b/Source/DotNET/Applications.Specs/Validation/for_ModelErrorExtensions/when_converting_nested_member_with_array.cs similarity index 100% rename from Specifications/Applications/Validation/for_ModelErrorExtensions/when_converting_nested_member_with_array.cs rename to Source/DotNET/Applications.Specs/Validation/for_ModelErrorExtensions/when_converting_nested_member_with_array.cs diff --git a/Specifications/Applications/Validation/for_ModelErrorExtensions/when_converting_simple_member.cs b/Source/DotNET/Applications.Specs/Validation/for_ModelErrorExtensions/when_converting_simple_member.cs similarity index 100% rename from Specifications/Applications/Validation/for_ModelErrorExtensions/when_converting_simple_member.cs rename to Source/DotNET/Applications.Specs/Validation/for_ModelErrorExtensions/when_converting_simple_member.cs diff --git a/Source/DotNET/Applications/Assembly.cs b/Source/DotNET/Applications/Assembly.cs new file mode 100644 index 00000000..006d12e4 --- /dev/null +++ b/Source/DotNET/Applications/Assembly.cs @@ -0,0 +1,6 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Cratis.Applications.MongoDB")] diff --git a/Source/DotNET/Applications/Internals.cs b/Source/DotNET/Applications/Internals.cs index 39bb1e01..16452630 100644 --- a/Source/DotNET/Applications/Internals.cs +++ b/Source/DotNET/Applications/Internals.cs @@ -10,13 +10,42 @@ namespace Cratis.Applications; /// internal static class Internals { + static IServiceProvider? _serviceProvider; + static ITypes? _types; + /// /// Internal: The service provider. /// - internal static IServiceProvider? ServiceProvider; + /// Thrown if the service provider has not been configured. + internal static IServiceProvider ServiceProvider + { + get + { + if (_serviceProvider == null) + { + throw new ServiceProviderNotConfigured(); + } + + return _serviceProvider; + } + set => _serviceProvider = value; + } /// /// Internal: The types. /// - internal static ITypes? Types; + /// Thrown if the type discovery system has not been configured. + internal static ITypes Types + { + get + { + if (_types == null) + { + throw new TypeDiscoverySystemNotConfigured(); + } + + return _types; + } + set => _types = value; + } } diff --git a/Source/DotNET/Applications/ServiceProviderNotConfigured.cs b/Source/DotNET/Applications/ServiceProviderNotConfigured.cs new file mode 100644 index 00000000..2cdcd057 --- /dev/null +++ b/Source/DotNET/Applications/ServiceProviderNotConfigured.cs @@ -0,0 +1,17 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Cratis.Applications; + +/// +/// Exception that gets thrown when the service provider has not been configured. +/// +public class ServiceProviderNotConfigured : Exception +{ + /// + /// Initializes a new instance of . + /// + public ServiceProviderNotConfigured() : base("Service provider has not been configured, have you forgotten to call 'UseCratisApplicationModel()' on your application during setup?") + { + } +} diff --git a/Source/DotNET/Applications/TypeDiscoverySystemNotConfigured.cs b/Source/DotNET/Applications/TypeDiscoverySystemNotConfigured.cs new file mode 100644 index 00000000..277bc268 --- /dev/null +++ b/Source/DotNET/Applications/TypeDiscoverySystemNotConfigured.cs @@ -0,0 +1,17 @@ +// Copyright (c) Cratis. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Cratis.Applications; + +/// +/// Exception that gets thrown when the service provider has not been configured. +/// +public class TypeDiscoverySystemNotConfigured : Exception +{ + /// + /// Initializes a new instance of . + /// + public TypeDiscoverySystemNotConfigured() : base("Type discovery system has not been configured, have you forgotten to call 'UseCratisApplicationModel()' on your host builder during setup?") + { + } +} diff --git a/Source/DotNET/Applications/Validation/ValidationMvcOptionsExtensions.cs b/Source/DotNET/Applications/Validation/ValidationMvcOptionsExtensions.cs index ec7d745e..8a9d3171 100644 --- a/Source/DotNET/Applications/Validation/ValidationMvcOptionsExtensions.cs +++ b/Source/DotNET/Applications/Validation/ValidationMvcOptionsExtensions.cs @@ -21,7 +21,7 @@ public static class ValidationMvcOptionsExtensions /// for building continuation. public static MvcOptions AddValidation(this MvcOptions options, ITypes types) { - options.ModelValidatorProviders.Add(new DiscoverableModelValidatorProvider(types, Internals.ServiceProvider!)); + options.ModelValidatorProviders.Add(new DiscoverableModelValidatorProvider(types, Internals.ServiceProvider)); return options; } } diff --git a/Source/DotNET/Directory.Build.props b/Source/DotNET/Directory.Build.props index 898b3395..fbc130eb 100644 --- a/Source/DotNET/Directory.Build.props +++ b/Source/DotNET/Directory.Build.props @@ -53,4 +53,14 @@ + + + + + + + + + + diff --git a/Specifications/GlobalUsings.cs b/Source/DotNET/GlobalUsings.Specs.cs similarity index 81% rename from Specifications/GlobalUsings.cs rename to Source/DotNET/GlobalUsings.Specs.cs index c49fd9b1..8badd2e0 100644 --- a/Specifications/GlobalUsings.cs +++ b/Source/DotNET/GlobalUsings.Specs.cs @@ -1,6 +1,8 @@ // Copyright (c) Cratis. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#pragma warning disable IDE0005 // Using directive is unnecessary. + global using Cratis.Specifications; global using Cratis.Types; global using Moq; diff --git a/Specifications/MongoDB/MongoDB.csproj b/Source/DotNET/MongoDB.Specs/MongoDB.Specs.csproj similarity index 70% rename from Specifications/MongoDB/MongoDB.csproj rename to Source/DotNET/MongoDB.Specs/MongoDB.Specs.csproj index c7d056fa..c5b4c0b8 100644 --- a/Specifications/MongoDB/MongoDB.csproj +++ b/Source/DotNET/MongoDB.Specs/MongoDB.Specs.csproj @@ -2,9 +2,10 @@ Cratis.Applications.MongoDB.Specs Cratis.Applications.MongoDB + true - + diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/InvocationTarget.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/InvocationTarget.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/InvocationTarget.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/InvocationTarget.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/given/an_interceptor.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/given/an_interceptor.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/given/an_interceptor.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/given/an_interceptor.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/when_intercepting/cancelled_method.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/when_intercepting/cancelled_method.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/when_intercepting/cancelled_method.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/when_intercepting/cancelled_method.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method_without_task.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method_without_task.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method_without_task.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/when_intercepting/faulted_method_without_task.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/when_intercepting/successful_method.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/when_intercepting/successful_method.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptor/when_intercepting/successful_method.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptor/when_intercepting/successful_method.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/InvocationTarget.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/InvocationTarget.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/InvocationTarget.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/InvocationTarget.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/given/an_interceptor.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/given/an_interceptor.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/given/an_interceptor.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/given/an_interceptor.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/cancelled_method.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/cancelled_method.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/cancelled_method.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/cancelled_method.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method_without_task.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method_without_task.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method_without_task.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/faulted_method_without_task.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/successful_method.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/successful_method.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/successful_method.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorForReturnValue/when_intercepting/successful_method.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorSelector/given/an_interceptor_selector.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorSelector/given/an_interceptor_selector.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorSelector/given/an_interceptor_selector.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorSelector/given/an_interceptor_selector.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods_with_return_value.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods_with_return_value.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods_with_return_value.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_async_methods_with_return_value.cs diff --git a/Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_sync_methods.cs b/Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_sync_methods.cs similarity index 100% rename from Specifications/MongoDB/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_sync_methods.cs rename to Source/DotNET/MongoDB.Specs/Resilience/for_MongoCollectionInterceptorSelector/when_selecting_interceptors/for_sync_methods.cs diff --git a/Specifications/MongoDB/for_AcronymFriendlyCamelCaseElementNameConvention/when_applying_convention_to_all_class_map_members.cs b/Source/DotNET/MongoDB.Specs/for_AcronymFriendlyCamelCaseElementNameConvention/when_applying_convention_to_all_class_map_members.cs similarity index 100% rename from Specifications/MongoDB/for_AcronymFriendlyCamelCaseElementNameConvention/when_applying_convention_to_all_class_map_members.cs rename to Source/DotNET/MongoDB.Specs/for_AcronymFriendlyCamelCaseElementNameConvention/when_applying_convention_to_all_class_map_members.cs diff --git a/Specifications/MongoDB/for_BsonClassMapExtensions/when_applying_conventions.cs b/Source/DotNET/MongoDB.Specs/for_BsonClassMapExtensions/when_applying_conventions.cs similarity index 100% rename from Specifications/MongoDB/for_BsonClassMapExtensions/when_applying_conventions.cs rename to Source/DotNET/MongoDB.Specs/for_BsonClassMapExtensions/when_applying_conventions.cs diff --git a/Specifications/MongoDB/for_BsonClassMapExtensions/when_unmapping_all_except/and_members_one_wants_to_keep_are_camel_cased.cs b/Source/DotNET/MongoDB.Specs/for_BsonClassMapExtensions/when_unmapping_all_except/and_members_one_wants_to_keep_are_camel_cased.cs similarity index 100% rename from Specifications/MongoDB/for_BsonClassMapExtensions/when_unmapping_all_except/and_members_one_wants_to_keep_are_camel_cased.cs rename to Source/DotNET/MongoDB.Specs/for_BsonClassMapExtensions/when_unmapping_all_except/and_members_one_wants_to_keep_are_camel_cased.cs diff --git a/Specifications/MongoDB/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_pack_other_than_specified_in_ignore_attribute_on_type.cs b/Source/DotNET/MongoDB.Specs/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_pack_other_than_specified_in_ignore_attribute_on_type.cs similarity index 100% rename from Specifications/MongoDB/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_pack_other_than_specified_in_ignore_attribute_on_type.cs rename to Source/DotNET/MongoDB.Specs/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_pack_other_than_specified_in_ignore_attribute_on_type.cs diff --git a/Specifications/MongoDB/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_same_as_specified_in_ignore_attribute_on_type.cs b/Source/DotNET/MongoDB.Specs/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_same_as_specified_in_ignore_attribute_on_type.cs similarity index 100% rename from Specifications/MongoDB/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_same_as_specified_in_ignore_attribute_on_type.cs rename to Source/DotNET/MongoDB.Specs/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_convention_same_as_specified_in_ignore_attribute_on_type.cs diff --git a/Specifications/MongoDB/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_with_ignore_attribute_ignoring_all.cs b/Source/DotNET/MongoDB.Specs/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_with_ignore_attribute_ignoring_all.cs similarity index 100% rename from Specifications/MongoDB/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_with_ignore_attribute_ignoring_all.cs rename to Source/DotNET/MongoDB.Specs/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_with_ignore_attribute_ignoring_all.cs diff --git a/Specifications/MongoDB/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_without_ignore_attribute.cs b/Source/DotNET/MongoDB.Specs/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_without_ignore_attribute.cs similarity index 100% rename from Specifications/MongoDB/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_without_ignore_attribute.cs rename to Source/DotNET/MongoDB.Specs/for_IgnoreConventionsAttributeFilter/when_asking_should_include_for_type_without_ignore_attribute.cs diff --git a/Source/DotNET/MongoDB/MongoDB.csproj b/Source/DotNET/MongoDB/MongoDB.csproj index 369ecb9b..ee538a82 100644 --- a/Source/DotNET/MongoDB/MongoDB.csproj +++ b/Source/DotNET/MongoDB/MongoDB.csproj @@ -3,9 +3,9 @@ Cratis.Applications.MongoDB Cratis.Applications.MongoDB - - - + + + @@ -14,4 +14,7 @@ + + + diff --git a/Source/DotNET/MongoDB/MongoDBCollectionExtensions.cs b/Source/DotNET/MongoDB/MongoDBCollectionExtensions.cs index 764290a3..d8d847d5 100644 --- a/Source/DotNET/MongoDB/MongoDBCollectionExtensions.cs +++ b/Source/DotNET/MongoDB/MongoDBCollectionExtensions.cs @@ -4,7 +4,10 @@ using System.Linq.Expressions; using System.Reactive.Subjects; using System.Reflection; +using Cratis.Applications; +using Cratis.Applications.Queries; using Cratis.Concepts; +using Microsoft.Extensions.DependencyInjection; using MongoDB.Bson; namespace MongoDB.Driver; @@ -164,6 +167,11 @@ static async Task> Observe( Func, ISubject> createSubject, Action, ISubject> onNext) { + var queryContext = Internals.ServiceProvider.GetService()!.Current; + if (queryContext.Paging.IsPaged) + { + } + var response = await findCall(); var documents = response.ToList(); var subject = createSubject(documents); @@ -188,70 +196,71 @@ static async Task> Observe( var pipeline = new EmptyPipelineDefinition>().Match(fullFilter); - var cursor = await collection.WatchAsync(pipeline, options); var idProperty = typeof(TDocument).GetProperty("Id", BindingFlags.Instance | BindingFlags.Public)!; +#pragma warning disable CA2000 // Dispose objects before losing scope + var cancellationTokenSource = new CancellationTokenSource(); +#pragma warning restore CA2000 // Dispose objects before losing scope + var cancellationToken = cancellationTokenSource.Token; - _ = Task.Run(async () => + IChangeStreamCursor> cursor = null!; + + try { - try - { - while (await cursor.MoveNextAsync()) + cursor = await collection.WatchAsync(pipeline, options); + await cursor.ForEachAsync( + changeDocument => { if (subject is Subject disposableSubject && disposableSubject.IsDisposed && subject is BehaviorSubject disposableBehaviorSubject && disposableBehaviorSubject.IsDisposed) { cursor.Dispose(); + cancellationTokenSource.Dispose(); return; } - if (!cursor.Current.Any()) continue; - - foreach (var changeDocument in cursor.Current) + if (changeDocument.DocumentKey.TryGetValue("_id", out var idValue)) { - if (changeDocument.DocumentKey.TryGetValue("_id", out var idValue)) + var id = BsonTypeMapper.MapToDotNetValue(idValue); + if (idProperty.PropertyType.IsConcept()) { - var id = BsonTypeMapper.MapToDotNetValue(idValue); - if (idProperty.PropertyType.IsConcept()) - { - id = ConceptFactory.CreateConceptInstance(idProperty.PropertyType, id); - } + id = ConceptFactory.CreateConceptInstance(idProperty.PropertyType, id); + } - var document = documents.Find(_ => idProperty.GetValue(_)!.Equals(id)); - if (changeDocument.OperationType == ChangeStreamOperationType.Delete && document is not null) - { - documents.Remove(document); - } - else if (document is not null) - { - var index = documents.IndexOf(document); - documents[index] = changeDocument.FullDocument; - } - else - { - documents.Add(changeDocument.FullDocument); - } + var document = documents.Find(_ => idProperty.GetValue(_)!.Equals(id)); + if (changeDocument.OperationType == ChangeStreamOperationType.Delete && document is not null) + { + documents.Remove(document); + } + else if (document is not null) + { + var index = documents.IndexOf(document); + documents[index] = changeDocument.FullDocument; + } + else + { + documents.Add(changeDocument.FullDocument); } } onNext(documents, subject); - } + }, + cancellationToken); + } + catch (ObjectDisposedException) + { + Console.WriteLine("Cursor disposed."); + cursor.Dispose(); + subject.OnCompleted(); + + if (subject is Subject disposableSubject) + { + disposableSubject.Dispose(); } - catch (ObjectDisposedException) + if (subject is BehaviorSubject disposableBehaviorSubject) { - Console.WriteLine("Cursor disposed."); - cursor.Dispose(); - subject.OnCompleted(); - - if (subject is Subject disposableSubject) - { - disposableSubject.Dispose(); - } - if (subject is BehaviorSubject disposableBehaviorSubject) - { - disposableBehaviorSubject.Dispose(); - } + disposableBehaviorSubject.Dispose(); } - }); + } subject.Subscribe(_ => { }, cursor.Dispose); diff --git a/Specifications/Orleans/Orleans.csproj b/Source/DotNET/Orleans.Specs/Orleans.Specs.csproj similarity index 78% rename from Specifications/Orleans/Orleans.csproj rename to Source/DotNET/Orleans.Specs/Orleans.Specs.csproj index e1bb0156..9d6413ff 100644 --- a/Specifications/Orleans/Orleans.csproj +++ b/Source/DotNET/Orleans.Specs/Orleans.Specs.csproj @@ -3,10 +3,11 @@ net8.0 Cratis.Applications.Orleans.Specs Cratis.Applications.Orleans + true - + diff --git a/Specifications/Orleans/StateMachines/BaseState.cs b/Source/DotNET/Orleans.Specs/StateMachines/BaseState.cs similarity index 100% rename from Specifications/Orleans/StateMachines/BaseState.cs rename to Source/DotNET/Orleans.Specs/StateMachines/BaseState.cs diff --git a/Specifications/Orleans/StateMachines/StateMachineForTesting.cs b/Source/DotNET/Orleans.Specs/StateMachines/StateMachineForTesting.cs similarity index 100% rename from Specifications/Orleans/StateMachines/StateMachineForTesting.cs rename to Source/DotNET/Orleans.Specs/StateMachines/StateMachineForTesting.cs diff --git a/Specifications/Orleans/StateMachines/StateMachineStateForTesting.cs b/Source/DotNET/Orleans.Specs/StateMachines/StateMachineStateForTesting.cs similarity index 100% rename from Specifications/Orleans/StateMachines/StateMachineStateForTesting.cs rename to Source/DotNET/Orleans.Specs/StateMachines/StateMachineStateForTesting.cs diff --git a/Specifications/Orleans/StateMachines/StateThatDoesNotSupportTransitioningFrom.cs b/Source/DotNET/Orleans.Specs/StateMachines/StateThatDoesNotSupportTransitioningFrom.cs similarity index 100% rename from Specifications/Orleans/StateMachines/StateThatDoesNotSupportTransitioningFrom.cs rename to Source/DotNET/Orleans.Specs/StateMachines/StateThatDoesNotSupportTransitioningFrom.cs diff --git a/Specifications/Orleans/StateMachines/StateThatSupportsTransitioningFrom.cs b/Source/DotNET/Orleans.Specs/StateMachines/StateThatSupportsTransitioningFrom.cs similarity index 100% rename from Specifications/Orleans/StateMachines/StateThatSupportsTransitioningFrom.cs rename to Source/DotNET/Orleans.Specs/StateMachines/StateThatSupportsTransitioningFrom.cs diff --git a/Specifications/Orleans/StateMachines/StateThatTransitionsOnEnter.cs b/Source/DotNET/Orleans.Specs/StateMachines/StateThatTransitionsOnEnter.cs similarity index 100% rename from Specifications/Orleans/StateMachines/StateThatTransitionsOnEnter.cs rename to Source/DotNET/Orleans.Specs/StateMachines/StateThatTransitionsOnEnter.cs diff --git a/Specifications/Orleans/StateMachines/StateThatTransitionsOnLeave.cs b/Source/DotNET/Orleans.Specs/StateMachines/StateThatTransitionsOnLeave.cs similarity index 100% rename from Specifications/Orleans/StateMachines/StateThatTransitionsOnLeave.cs rename to Source/DotNET/Orleans.Specs/StateMachines/StateThatTransitionsOnLeave.cs diff --git a/Specifications/Orleans/StateMachines/StateWithAllowedTransitionState.cs b/Source/DotNET/Orleans.Specs/StateMachines/StateWithAllowedTransitionState.cs similarity index 100% rename from Specifications/Orleans/StateMachines/StateWithAllowedTransitionState.cs rename to Source/DotNET/Orleans.Specs/StateMachines/StateWithAllowedTransitionState.cs diff --git a/Specifications/Orleans/StateMachines/StateWithoutAllowedTransitionState.cs b/Source/DotNET/Orleans.Specs/StateMachines/StateWithoutAllowedTransitionState.cs similarity index 100% rename from Specifications/Orleans/StateMachines/StateWithoutAllowedTransitionState.cs rename to Source/DotNET/Orleans.Specs/StateMachines/StateWithoutAllowedTransitionState.cs diff --git a/Specifications/Orleans/StateMachines/UnknownState.cs b/Source/DotNET/Orleans.Specs/StateMachines/UnknownState.cs similarity index 100% rename from Specifications/Orleans/StateMachines/UnknownState.cs rename to Source/DotNET/Orleans.Specs/StateMachines/UnknownState.cs diff --git a/Specifications/Orleans/StateMachines/for_State/when_asking_can_transition/and_it_does_not_have_state_as_allowed.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_State/when_asking_can_transition/and_it_does_not_have_state_as_allowed.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_State/when_asking_can_transition/and_it_does_not_have_state_as_allowed.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_State/when_asking_can_transition/and_it_does_not_have_state_as_allowed.cs diff --git a/Specifications/Orleans/StateMachines/for_State/when_asking_can_transition/and_it_has_state_as_allowed.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_State/when_asking_can_transition/and_it_has_state_as_allowed.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_State/when_asking_can_transition/and_it_has_state_as_allowed.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_State/when_asking_can_transition/and_it_has_state_as_allowed.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/given/a_state_machine.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/given/a_state_machine.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/given/a_state_machine.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/given/a_state_machine.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/given/a_state_machine_with_well_known_states.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/given/a_state_machine_with_well_known_states.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/given/a_state_machine_with_well_known_states.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/given/a_state_machine_with_well_known_states.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_invalid_initial_state_type.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_invalid_initial_state_type.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_invalid_initial_state_type.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_invalid_initial_state_type.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_known_current_state.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_known_current_state.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_known_current_state.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_known_current_state.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_known_initial_state_type.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_known_initial_state_type.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_known_initial_state_type.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_known_initial_state_type.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_unknown_current_state.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_unknown_current_state.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_unknown_current_state.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_unknown_current_state.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_unknown_initial_state_type.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_unknown_initial_state_type.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_unknown_initial_state_type.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_unknown_initial_state_type.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_valid_initial_state_type.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_valid_initial_state_type.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_activating/with_valid_initial_state_type.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_activating/with_valid_initial_state_type.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_allows_it.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_allows_it.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_allows_it.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_allows_it.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_does_not_allow_it.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_does_not_allow_it.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_does_not_allow_it.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_asking_can_transition_to/and_state_does_not_allow_it.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is_not.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is_not.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is_not.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_checking_if_is_in_active_state/and_it_is_not.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_deactivating_grain.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_deactivating_grain.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_deactivating_grain.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_deactivating_grain.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_transitioning/and_state_can_be_transitioned_to.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_transitioning/and_state_can_be_transitioned_to.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_transitioning/and_state_can_be_transitioned_to.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_transitioning/and_state_can_be_transitioned_to.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_transitioning/and_state_is_unknown_state_type.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_transitioning/and_state_is_unknown_state_type.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_transitioning/and_state_is_unknown_state_type.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_transitioning/and_state_is_unknown_state_type.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_enter.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_enter.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_enter.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_enter.cs diff --git a/Specifications/Orleans/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_leave.cs b/Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_leave.cs similarity index 100% rename from Specifications/Orleans/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_leave.cs rename to Source/DotNET/Orleans.Specs/StateMachines/for_StateMachine/when_transitioning/and_state_transitions_to_other_state_during_on_leave.cs diff --git a/Specifications/Directory.Build.props b/Specifications/Directory.Build.props deleted file mode 100644 index 55a6395d..00000000 --- a/Specifications/Directory.Build.props +++ /dev/null @@ -1,29 +0,0 @@ - - - - - net8.0 - true - disable - - false - true - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - diff --git a/Specifications/WarningsToIgnore.props b/Specifications/WarningsToIgnore.props deleted file mode 100644 index 79a13c69..00000000 --- a/Specifications/WarningsToIgnore.props +++ /dev/null @@ -1,69 +0,0 @@ - - - - $(NoWarn); - CA1001; - CA1008; - CA1024; - CA1034; - CA1051; - CA1305; - CA1707; - CA1813; - CA1852; - CA1861; - CA2201; - CA2211; - CA2252; - CS8632; - CS8618; - CS8981; - CS9113; - IDE0005; - IDE0044; - IDE0051; - IDE0052; - IDE0060; - IDE1006; - SA0001; - SA1116; - SA1122; - SA1134; - SA1201; - SA1202; - SA1203; - SA1204; - SA1214; - SA1303; - SA1304; - SA1306; - SA1307; - SA1311; - SA1312; - SA1313; - SA1402; - SA1500; - SA1502; - SA1507; - SA1600; - RCS1018; - RCS1036; - RCS1090; - RCS1163; - RCS1169; - RCS1202; - RCS1213; - RCS1225; - RCS1241; - MA0016; - MA0036; - MA0041; - MA0044; - MA0048; - MA0069; - MA0096; - MA0097; - MA0132; - - -