1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using Microsoft . AspNetCore . Components ;
4
5
using Microsoft . AspNetCore . Components . Discovery ;
5
6
using Microsoft . AspNetCore . Components . Endpoints ;
6
7
using Microsoft . AspNetCore . Components . Web ;
@@ -10,18 +11,15 @@ namespace Microsoft.AspNetCore.Builder;
10
11
/// <summary>
11
12
/// Builds conventions that will be used for customization of <see cref="EndpointBuilder"/> instances.
12
13
/// </summary>
13
-
14
- // TODO: This will have APIs to add and remove entire assemblies from the list of considered endpoints
15
- // as well as adding/removing individual pages as endpoints.
16
- public class RazorComponentEndpointConventionBuilder : IEndpointConventionBuilder
14
+ public sealed class RazorComponentsEndpointConventionBuilder : IEndpointConventionBuilder
17
15
{
18
16
private readonly object _lock ;
19
17
private readonly ComponentApplicationBuilder _builder ;
20
18
private readonly RazorComponentDataSourceOptions _options ;
21
19
private readonly List < Action < EndpointBuilder > > _conventions ;
22
20
private readonly List < Action < EndpointBuilder > > _finallyConventions ;
23
21
24
- internal RazorComponentEndpointConventionBuilder (
22
+ internal RazorComponentsEndpointConventionBuilder (
25
23
object @lock ,
26
24
ComponentApplicationBuilder builder ,
27
25
RazorComponentDataSourceOptions options ,
@@ -38,43 +36,14 @@ internal RazorComponentEndpointConventionBuilder(
38
36
/// <summary>
39
37
/// Gets the <see cref="ComponentApplicationBuilder"/> that is used to build the endpoints.
40
38
/// </summary>
41
- public ComponentApplicationBuilder ApplicationBuilder => _builder ;
42
-
43
- /// <summary>
44
- /// Configures the <see cref="RenderMode.WebAssembly"/> for this application.
45
- /// </summary>
46
- /// <returns>The <see cref="RazorComponentEndpointConventionBuilder"/>.</returns>
47
- public RazorComponentEndpointConventionBuilder AddWebAssemblyRenderMode ( )
48
- {
49
- for ( var i = 0 ; i < _options . ConfiguredRenderModes . Count ; i ++ )
50
- {
51
- var mode = _options . ConfiguredRenderModes [ i ] ;
52
- if ( mode is WebAssemblyRenderMode )
53
- {
54
- return this ;
55
- }
56
- }
57
-
58
- _options . ConfiguredRenderModes . Add ( RenderMode . WebAssembly ) ;
59
-
60
- return this ;
61
- }
39
+ internal ComponentApplicationBuilder ApplicationBuilder => _builder ;
62
40
63
41
/// <summary>
64
42
/// Configures the <see cref="RenderMode.Server"/> for this application.
65
43
/// </summary>
66
- /// <returns>The <see cref="RazorComponentEndpointConventionBuilder "/>.</returns>
67
- public RazorComponentEndpointConventionBuilder AddServerRenderMode ( )
44
+ /// <returns>The <see cref="RazorComponentsEndpointConventionBuilder "/>.</returns>
45
+ public RazorComponentsEndpointConventionBuilder AddServerRenderMode ( )
68
46
{
69
- for ( var i = 0 ; i < _options . ConfiguredRenderModes . Count ; i ++ )
70
- {
71
- var mode = _options . ConfiguredRenderModes [ i ] ;
72
- if ( mode is ServerRenderMode )
73
- {
74
- return this ;
75
- }
76
- }
77
-
78
47
_options . ConfiguredRenderModes . Add ( RenderMode . Server ) ;
79
48
80
49
return this ;
@@ -103,4 +72,13 @@ public void Finally(Action<EndpointBuilder> finallyConvention)
103
72
_finallyConventions . Add ( finallyConvention ) ;
104
73
}
105
74
}
75
+
76
+ /// <summary>
77
+ /// Adds the given <paramref name="renderMode"/> to the list of configured render modes if not present.
78
+ /// </summary>
79
+ /// <param name="renderMode">The <see cref="IComponentRenderMode"/> to add.</param>
80
+ public void AddRenderMode ( IComponentRenderMode renderMode )
81
+ {
82
+ _options . ConfiguredRenderModes . Add ( renderMode ) ;
83
+ }
106
84
}
0 commit comments