|
19 | 19 |
|
20 | 20 | var host = builder.Build();
|
21 | 21 |
|
22 |
| -var pipelineBuilder = host.Services.GetRequiredService<GeneratorPipelineBuilder>(); |
23 |
| -var pipeline = pipelineBuilder.Build("TodoList.Blazor.Output"); |
| 22 | +await host.Services.GetRequiredService<GeneratorWorkspaceBuilder>() |
| 23 | + .AddCommandLineActions() |
| 24 | + .AddCSharpGeneration() |
| 25 | + .InvokeAsync<GenerateTodoListApp>("TodoList.Blazor.Output"); |
24 | 26 |
|
25 |
| -var webProject = new DotNetProjectReference("TodoList.Web/TodoList.Web.csproj"); |
| 27 | +class GenerateTodoListApp( |
| 28 | + CommandLineActions commandLine, |
| 29 | + CSharpActions csharp, |
| 30 | + CSharpGenerator csharpGenerator) : IVoidAction |
| 31 | +{ |
| 32 | + public async Task InvokeAsync() |
| 33 | + { |
| 34 | + await csharp.CreateSdkGlobalAsync( |
| 35 | + new CreateSdkGlobalParameters(DotNetSdkVersion.Net8)); |
| 36 | + |
| 37 | + var webProject = new DotNetProjectReference("TodoList.Web/TodoList.Web.csproj"); |
| 38 | + |
| 39 | + await commandLine.ExecuteCommandLineAsync( |
| 40 | + new ExecuteCommandLineParameters( |
| 41 | + $"dotnet new blazor -o {webProject.Name} --interactivity server --empty")); |
26 | 42 |
|
27 |
| -pipeline |
28 |
| - .AddStep(ctx => new CreateSdkGlobal(DotNetSdkVersion.Net8)) |
29 |
| - .AddStep(ctx => |
30 |
| - new RunCommand( |
31 |
| - $"dotnet new blazor -o {webProject.Name} --interactivity server --empty")) |
32 |
| - .AddStep(ctx => |
33 |
| - new TransformClass( |
34 |
| - webProject, |
35 |
| - "TodoList.Web/Program.cs", |
36 |
| - """ |
37 |
| - Use reflection to register any classes in the current assembly |
38 |
| - that have a name that ends in `Service`, register them as scoped services. |
39 |
| - Register the default interface if possible. For example if TestService implements |
40 |
| - ITestService it should be registered as `services.AddScoped<ITestService, TestService>()` |
41 |
| - Make sure the services are registered before the app container is built. |
42 |
| - """)) |
43 |
| - .AddStep(ctx => |
44 |
| - new GenerateClass( |
45 |
| - webProject, |
46 |
| - "TodoList.Web.Models.TodoItem", |
47 |
| - """ |
48 |
| - A model that represents a todo item. It should have the following properties: |
49 |
| - Id (guid) |
50 |
| - Title |
51 |
| - Completed |
52 |
| - Notes |
53 |
| - """)) |
54 |
| - .AddStep(ctx => |
55 |
| - new GenerateClass( |
56 |
| - webProject, |
57 |
| - "TodoList.Web.Service.TodoService", |
58 |
| - """ |
59 |
| - A service that provides CRUD actions for todo list items. Assume todo list items are of type |
60 |
| - TodoList.Web.Models.TodoItem. The items should be stored in a dictionary. Getting all items should return a list. |
61 |
| - """)); |
62 |
| - // .AddStep(ctx => |
63 |
| - // new GenerateClasses( |
64 |
| - // webProject, |
65 |
| - // "TodoList.Web", |
66 |
| - // """ |
67 |
| - // A Blazor page component with route '/todo' that shows a listing of todo items and the supporting |
68 |
| - // service that holds the todo items in memory. |
69 |
| - // """)) |
70 |
| - // .AddStep(ctx => |
71 |
| - // new GenerateClasses( |
72 |
| - // webProject, |
73 |
| - // "TodoList.Web", |
74 |
| - // """ |
75 |
| - // A single Blazor page component at Components/Pages/Home.razor. |
76 |
| - // Don't generate any other pages. |
77 |
| - // The page contents should be: |
78 |
| - // A basic heading. |
79 |
| - // A link to "ToDo Items" at URL /todo. |
80 |
| - // """)) |
81 |
| - // .AddStep(ctx => |
82 |
| - // new RunCommand("dotnet run", webProject.RelativeRoot, Interactive: true)); |
| 43 | + await csharpGenerator.TransformClassAsync( |
| 44 | + new TransformClassParameters( |
| 45 | + webProject, |
| 46 | + "TodoList.Web/Program.cs", |
| 47 | + """ |
| 48 | + Use reflection to register any classes in the current assembly |
| 49 | + that have a name that ends in `Service`, register them as scoped services. |
| 50 | + Register the default interface if possible. For example if TestService implements |
| 51 | + ITestService it should be registered as `services.AddScoped<ITestService, TestService>()` |
| 52 | + Make sure the services are registered before the app container is built. |
| 53 | + """)); |
83 | 54 |
|
84 |
| -await pipeline.RunAsync(); |
| 55 | + var todoItem = await csharpGenerator.GenerateClassAsync( |
| 56 | + new GenerateClassParameters( |
| 57 | + webProject, |
| 58 | + "TodoList.Web.Models.TodoItem", |
| 59 | + """ |
| 60 | + A model that represents a todo item. It should have the following properties: |
| 61 | + Id (guid) |
| 62 | + Title |
| 63 | + Completed |
| 64 | + Notes |
| 65 | + """)); |
| 66 | + |
| 67 | + var todoService = await csharpGenerator.GenerateClassAsync( |
| 68 | + new GenerateClassParameters( |
| 69 | + webProject, |
| 70 | + "TodoList.Web.Service.TodoService", |
| 71 | + """ |
| 72 | + A service that provides CRUD actions for todo list items. Assume todo list items are of type |
| 73 | + TodoList.Web.Models.TodoItem. The items should be stored in a dictionary. Getting all items should return a list. |
| 74 | + """) |
| 75 | + { |
| 76 | + ContextMemoryItems = [todoItem] |
| 77 | + }); |
| 78 | + |
| 79 | + await csharpGenerator.GenerateRazorComponentAsync( |
| 80 | + new GenerateRazorComponentParameters( |
| 81 | + webProject, |
| 82 | + "Components/Pages/TodoPage", |
| 83 | + """ |
| 84 | + A Blazor page component with route '/todo' that Injects TodoList.Web.Service.TodoService and |
| 85 | + shows a listing of TodoList.Web.Models.TodoItem items. |
| 86 | + """) |
| 87 | + { |
| 88 | + ContextMemoryItems = [todoItem, todoService] |
| 89 | + }); |
| 90 | + |
| 91 | + await csharpGenerator.GenerateRazorComponentAsync( |
| 92 | + new GenerateRazorComponentParameters( |
| 93 | + webProject, |
| 94 | + "Components/Pages/Home", |
| 95 | + """ |
| 96 | + A Blazor page component |
| 97 | + The page contents should be: |
| 98 | + A basic heading with a creative todo related title. |
| 99 | + A link to "Todo Items" at URL /todo. |
| 100 | + """)); |
| 101 | + |
| 102 | + await commandLine.ExecuteCommandLineAsync( |
| 103 | + new ExecuteCommandLineParameters( |
| 104 | + "dotnet run", webProject.RelativeRoot, Interactive: true)); |
| 105 | + } |
| 106 | +} |
85 | 107 |
|
0 commit comments