Skip to content

Commit 54b1ac3

Browse files
chore(common): WASM service registration changes for 3.2
1 parent af17e79 commit 54b1ac3

File tree

2 files changed

+81
-30
lines changed

2 files changed

+81
-30
lines changed

getting-started/client-blazor.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,34 @@ For client-side `Blazor App`, we recommend the usage of `Blazor (ASP.NET Hosted)
5555

5656
1. @[template](/_contentTemplates/common/js-interop-file.md#add-js-interop-file-to-getting-started-client)
5757

58-
1. Open the `~/Startup.cs` file in the client web application and register the Telerik Blazor service:
58+
1. Open the `~/Program.cs` file in the client web application and register the Telerik Blazor service:
5959

6060
**C#**
6161

62-
namespace MyBlazorAppName.Client
63-
{
64-
public class Startup
65-
{
66-
public void ConfigureServices(IServiceCollection services)
67-
{
68-
//more code may be present here
69-
services.AddTelerikBlazor();
70-
}
71-
72-
//more code may be present here
73-
}
74-
}
62+
using Microsoft.AspNetCore.Blazor.Hosting;
63+
using Microsoft.Extensions.DependencyInjection;
64+
using System.Threading.Tasks;
65+
66+
namespace ClientBlazorProject.Client // make sure this matches your actual WASM project namespace
67+
{
68+
public class Program
69+
{
70+
public static async Task Main(string[] args)
71+
{
72+
// sample host builder for a WASM app, yours may differ
73+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
74+
builder.RootComponents.Add<App>("app");
75+
// there may be more code here
76+
77+
// register the Telerik services
78+
builder.Services.AddTelerikBlazor();
79+
80+
// there may be more code here
81+
// sample host builder for a WASM app, yours may differ
82+
await builder.Build().RunAsync();
83+
}
84+
}
85+
}
7586

7687
1. Add the following to your **`~/_Imports.razor`** file so the project recognizes our components in all files:
7788

getting-started/what-you-need.md

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,13 @@ Note that
7979

8080
## Project Configuration
8181

82-
To have the framework recognize the Telerik Components, you must register them in the `Startup.cs` file of your Blazor project (if you are using client-side Blazor, this is the Client web application's file):
82+
To use the Telerik Components, you must add a few items to your projects. Depending on the type of project (server-side or client-side), the steps differ slightly in syntax.
8383

84-
````Startup.cs
85-
namespace MyBlazorAppName
86-
{
87-
public class Startup
88-
{
89-
public void ConfigureServices(IServiceCollection services)
90-
{
91-
//more code may be present here
92-
services.AddTelerikBlazor();
93-
}
84+
1. Follow the [Common Configuration](#common-configuration) instructions
85+
2. Follow the section for your project type - [Client-side (WASM)](#client-side-project-specifics) or [Server-side](#server-side-project-specifics)
9486

95-
//more code may be present here
96-
}
97-
}
98-
````
87+
88+
### Common Configuration
9989

10090
You can have the project recognize all our components without explicit `@using` statements on every `.razor` file. It is enough to add the following to your **`~/_Imports.razor`** file:
10191

@@ -111,11 +101,61 @@ To allow working with detached popups (for example, dropdown lists, menus, grid
111101
@[template](/_contentTemplates/common/get-started.md#telerik-main-container-snippet)
112102
````
113103

114-
### Client-side Project Considerations
104+
### Client-side Project Specifics
115105

116106
If you are using a **client-side Blazor** project:
117107
@[template](/_contentTemplates/common/issues-and-warnings.md#mono-linker-issue)
118108

109+
The final step is to register the Telerik services. In a client-side Blazor project, you do that in the `Program.cs` file of the WebAssembly (Client) project:
110+
111+
````CS
112+
using Microsoft.AspNetCore.Blazor.Hosting;
113+
using Microsoft.Extensions.DependencyInjection;
114+
using System.Threading.Tasks;
115+
116+
namespace ClientBlazorProject.Client // make sure this matches your actual WASM project namespace
117+
{
118+
public class Program
119+
{
120+
public static async Task Main(string[] args)
121+
{
122+
// sample host builder for a WASM app, yours may differ
123+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
124+
builder.RootComponents.Add<App>("app");
125+
// there may be more code here
126+
127+
// register the Telerik services
128+
builder.Services.AddTelerikBlazor();
129+
130+
// there may be more code here
131+
// sample host builder for a WASM app, yours may differ
132+
await builder.Build().RunAsync();
133+
}
134+
}
135+
}
136+
````
137+
138+
139+
### Server-side Project Specifics
140+
141+
The final step is to register the Telerik services. In a server-side Blazor project, you do that in the `Startup.cs` file:
142+
143+
````CS
144+
namespace MyBlazorAppName
145+
{
146+
public class Startup
147+
{
148+
public void ConfigureServices(IServiceCollection services)
149+
{
150+
//more code may be present here
151+
services.AddTelerikBlazor();
152+
}
153+
154+
//more code may be present here
155+
}
156+
}
157+
````
158+
119159

120160
## See Also
121161

0 commit comments

Comments
 (0)