Skip to content

Commit

Permalink
Enables the selection of more than one template
Browse files Browse the repository at this point in the history
  • Loading branch information
david-acm committed Apr 30, 2024
1 parent 02e921b commit 2d0fa93
Show file tree
Hide file tree
Showing 32 changed files with 126 additions and 116 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dotnet new modulith -n eShop --with-module Payments

``` pwsh
cd eShop
dotnet new modulith-proj --add-module Shipments --to eShop
dotnet new modulith --add basic --with-name Shipments --to eShop
```

*⚠️ `cd` into the solution folder to add the module inside the solution.*
Expand Down
6 changes: 4 additions & 2 deletions test.pwsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cd /Users/davidchaparro/RiderProjects/modulith/test/
rm -rf /Users/davidchaparro/RiderProjects/modulith/test/**
dotnet new uninstall /Users/davidchaparro/RiderProjects/modulith/working/content/modulith
dotnet new install /Users/davidchaparro/RiderProjects/modulith/working/content/modulith
dotnet new modulith --solution -n eShop --with-module Payments
dotnet new modulith -n eShop --with-module Payments

cd eShop
dotnet new modulith --add-module --with-name Shipments --to eShop
dotnet new modulith --add basic-module --with-name Shipments --to eShop
dotnet new modulith --add ddd-module --with-name Billing --to eShop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Modulith.DddModule.Contracts;
namespace Modulith.NewModule.Contracts;

public class Class1
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Modulith.DddModule\Modulith.DddModule.csproj" />
<ProjectReference Include="..\Modulith.NewModule\Modulith.NewModule.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using ArchUnitNET.xUnit;
using static ArchUnitNET.Fluent.ArchRuleDefinition;

namespace Modulith.DddModule.Tests;
namespace Modulith.NewModule.Tests;

public class DddModuleTypesShould
public class NewModuleTypesShould
{
private static readonly Architecture Architecture =
new ArchLoader()
Expand All @@ -17,8 +17,8 @@ public void BeInternal()
{
var domainTypes = Types()
.That()
.ResideInNamespace("Modulith.DddModule.*", useRegularExpressions: true)
.And().AreNot([typeof(AssemblyInfo), typeof(DddModuleModuleHostApplicationBuilderExtensions)])
.ResideInNamespace("Modulith.NewModule.*", useRegularExpressions: true)
.And().AreNot([typeof(AssemblyInfo), typeof(NewModuleModuleHostApplicationBuilderExtensions)])
.As("Module types");

var rule = domainTypes.Should().BeInternal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using ArchUnitNET.Loader;
using ArchUnitNET.xUnit;

namespace Modulith.DddModule.Tests;
namespace Modulith.NewModule.Tests;

public class DomainTypesShould
{
Expand All @@ -17,14 +17,14 @@ public void NotDependOnApiTypes()
{
var domainTypes = ArchRuleDefinition.Types()
.That()
.ResideInNamespace("Modulith.DddModule.Domain.*", useRegularExpressions: true)
.And().AreNot([typeof(AssemblyInfo), typeof(DddModuleModuleHostApplicationBuilderExtensions)])
.ResideInNamespace("Modulith.NewModule.Domain.*", useRegularExpressions: true)
.And().AreNot([typeof(AssemblyInfo), typeof(NewModuleModuleHostApplicationBuilderExtensions)])
.As("Domain types");

var apiTypes = ArchRuleDefinition.Types()
.That()
.ResideInNamespace("Modulith.DddModule.Api.*", useRegularExpressions: true)
.And().AreNot([typeof(AssemblyInfo), typeof(DddModuleModuleHostApplicationBuilderExtensions)])
.ResideInNamespace("Modulith.NewModule.Api.*", useRegularExpressions: true)
.And().AreNot([typeof(AssemblyInfo), typeof(NewModuleModuleHostApplicationBuilderExtensions)])
.As("Api types");

var rule = domainTypes.Should().NotDependOnAny(apiTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Modulith.DddModule\Modulith.DddModule.csproj" />
<ProjectReference Include="..\Modulith.NewModule\Modulith.NewModule.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using FastEndpoints;
using FastEndpoints.Testing;
using FluentAssertions;
using Modulith.DddModule.Api;
using Modulith.NewModule.Api;

namespace Modulith.DddModule.Tests;
namespace Modulith.NewModule.Tests;

public class WeatherForecastEndpointShould(DddModuleFixture fixture) : TestBase<DddModuleFixture>
public class WeatherForecastEndpointShould(NewModuleFixture fixture) : TestBase<NewModuleFixture>
{
[Fact]
public async Task ReturnWeatherForecastDataAsync()
Expand All @@ -17,7 +17,7 @@ public async Task ReturnWeatherForecastDataAsync()
}
}

public class DddModuleFixture : AppFixture<AssemblyInfo>
public class NewModuleFixture : AppFixture<AssemblyInfo>
{
protected override async Task SetupAsync()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Modulith.DddModule.Api;
namespace Modulith.NewModule.Api;

internal interface IWeatherForecastService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FastEndpoints;

namespace Modulith.DddModule.Api;
namespace Modulith.NewModule.Api;

internal record WeatherForecastResponse(DateOnly Date, int TemperatureC, string? Summary);

Expand All @@ -9,7 +9,7 @@ internal class WeatherForecastEndpoint(IWeatherForecastService weatherForecastSe
public override void Configure()
{
AllowAnonymous();
Get("/DddModule/weatherforecast");
Get("/NewModule/weatherforecast");
}

public override async Task HandleAsync(CancellationToken ct)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Modulith.DddModule.Api;
namespace Modulith.NewModule.Api;

internal class WeatherForecastService : IWeatherForecastService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Modulith.DddModule.Tests")]
namespace Modulith.DddModule;
[assembly: InternalsVisibleTo("Modulith.NewModule.Tests")]
namespace Modulith.NewModule;

public class AssemblyInfo { }

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@Modulith.Web_HostAddress = http://localhost:5183

GET {{Modulith.Web_HostAddress}}/DddModule/weatherforecast/
GET {{Modulith.Web_HostAddress}}/NewModule/weatherforecast/
Accept: application/json

###
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Modulith.DddModule.Api;
using Modulith.NewModule.Api;

namespace Modulith.DddModule;
namespace Modulith.NewModule;

public static class DddModuleModuleHostApplicationBuilderExtensions
public static class NewModuleModuleHostApplicationBuilderExtensions
{
public static void AddDddModuleServices(this IHostApplicationBuilder builder)
public static void AddNewModuleServices(this IHostApplicationBuilder builder)
{
var logger = GetLogger(builder);
builder.Services.AddMediatR(
c => c.RegisterServicesFromAssemblies(typeof(AssemblyInfo).Assembly));

builder.Services.AddScoped<IWeatherForecastService, WeatherForecastService>();

logger.LogInformation("⚙️ DddModule module services registered");
logger.LogInformation("⚙️ NewModule module services registered");
}

private static ILogger<WebApplicationBuilder> GetLogger(IHostApplicationBuilder builder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Modulith.DddModule.Domain;
namespace Modulith.NewModule.Domain;

public enum Summary
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Modulith.DddModule.Api;
using Modulith.NewModule.Api;

namespace Modulith.DddModule.Domain;
namespace Modulith.NewModule.Domain;

internal class Weather(DateOnly date, int temperatureC, Summary summary)
{
Expand Down
112 changes: 60 additions & 52 deletions working/content/modulith/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"$schema": "http://json.schemastore.org/template",
"$comment": "See https://aka.ms/template-json-reference for complete configuration description. Complete TODOs below and remove the $comment properties. It is recommended to use the JSON editor that supports schema hints to get more information about defined JSON properties and their description.",
"$schema": "http://json.schemastore.org/add",
"author": "David Chaparro",
"classifications": [
"Web",
Expand All @@ -11,7 +10,7 @@
"Monolith"
],
"name": "modulith",
"description": "A solution template for creating a Modular Monolithic Web API using FastEndpoints and MediatR",
"description": "A solution add for creating a Modular Monolithic Web API using FastEndpoints and MediatR",
"precedence": "0",
"identity": "Davidc.Modulith.1.0",
"shortName": "modulith",
Expand All @@ -24,33 +23,47 @@
"preferDefaultName": true,
"preferNameDirectory": true,
"symbols": {
"solution": {
"add": {
"type": "parameter",
"datatype": "bool",
"defaultValue": true
"datatype": "choice",
"choices": [
{
"choice": "solution",
"description": "Starter solution with one basic module"
},
{
"choice": "basic-module",
"description": "Basic module"
},
{
"choice": "ddd-module",
"description": "Ddd module"
}
],
"defaultValue": "solution",
"description": "The type of authentication to use"
},
"add-module": {
"type": "parameter",
"datatype": "bool",
"defaultValue": false
"IsSolution": {
"type": "computed",
"value": "(add == \"solution\")"
},
"with-module": {
"type": "parameter",
"datatype": "string",
"defaultValue": "FirstModule",
"fileRename": "NewModule",
"replaces": "NewModule",
"isEnabled": "(solution)",
"isRequired": "(solution && !add-module)"
"isEnabled": "(add == \"solution\")",
"isRequired": "(add == \"solution\")"
},
"with-name": {
"type": "parameter",
"datatype": "string",
"defaultValue": "MyModule",
"fileRename": "NewModule",
"replaces": "NewModule",
"isEnabled": "(add-module)",
"isRequired": "(add-module)"
"isEnabled": "(add != \"solution\")",
"isRequired": "(add != \"solution\")"
},
"to": {
"displayName": "Existing project relative path",
Expand All @@ -65,68 +78,63 @@
{
"source": "./",
"target": "./",
"condition": "(solution && !add-module)",
"modifiers": [
{
"condition": "(solution)",
"include": [
"Modulith.SharedKernel/**/*",
"Modulith.Web/**/*",
"NewModule/**/*",
".gitignore",
"Directory.Build.props",
"Modulith.sln"
],
"exclude": [
"DddModule/**",
"TestModulith.sln"
]
}
"condition": "(IsSolution)",
"include": [
"Modulith.SharedKernel/**/*",
"Modulith.Web/**/*",
"NewModule/**/*",
".gitignore",
"Directory.Build.props",
"Modulith.sln"
]
},
{
"source": ".",
"target": "./",
"condition": "(add-module)",
"condition": "(add == \"basic-module\")",
"rename": {
"NewModule/" : "NewModule/"
"NewModule/": "NewModule/"
},
"include": [
"NewModule/**/*"
]
},
{
"source": ".",
"target": "./",
"condition": "(add == \"ddd-module\")",
"rename": {
"DddModule": "NewModule"
},
"modifiers": [
{
"condition": "(solution)",
"exclude": [
"Modulith.SharedKernel/**/*",
"Modulith.Web/**/*",
"DddModule/**/*",
".gitignore",
"Directory.Build.props",
"Modulith.sln",
"TestModulith.sln"
],
"include": [
"NewModule/**/*"
]
"rename": {
"DddModule": "NewModule"
}
}
],
"include": [
"DddModule/**/*"
]
}
],
"primaryOutputs": [
{
"condition": "(add-module)",
"condition": "(!IsSolution)",
"path": "NewModule/Modulith.NewModule/Modulith.NewModule.csproj"
},
{
"condition": "(add-module)",
"condition": "(!IsSolution)",
"path": "NewModule/Modulith.NewModule.Contracts/Modulith.NewModule.Contracts.csproj"
},
{
"condition": "(add-module)",
"condition": "(!IsSolution)",
"path": "NewModule/Modulith.NewModule.Tests/Modulith.NewModule.Tests.csproj"
}
],
"postActions": [
{
"condition": "(add-module)",
"condition": "(!IsSolution)",
"description": "Add projects to solution",
"manualInstructions": [
{
Expand All @@ -137,7 +145,7 @@
"continueOnError": true
},
{
"condition": "(add-module)",
"condition": "(!IsSolution)",
"description": "Adding a reference to Web project",
"actionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"continueOnError": true,
Expand All @@ -159,7 +167,7 @@
}
},
{
"condition": "(add-module)",
"condition": "(!IsSolution)",
"description": "Adding a reference to SharedKernel",
"actionId": "B17581D1-C5C9-4489-8F0A-004BE667B814",
"continueOnError": true,
Expand Down
Loading

0 comments on commit 2d0fa93

Please sign in to comment.