Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ImplicitUsings in project and item templates #373

Merged
merged 6 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"replaces": "NamespaceName",
"defaultValue": "Handlers"
},
"ImplicitUsings": {
"type": "bind",
"binding": "msbuild:ImplicitUsings"
},
"messagetype": {
"type": "parameter",
"description": "The type of message that will be handled by the message handler.",
Expand Down
6 changes: 5 additions & 1 deletion src/ParticularTemplates/Handler/ClassName.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#if (!ImplicitUsings)
using System;
using System.Threading.Tasks;
#endif
using Microsoft.Extensions.Logging;
#if (!ImplicitUsings)
using NServiceBus;
using System.Threading.Tasks;
#endif

namespace NamespaceName
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
"UsesSQL": {
"type": "computed",
"value": "(transport == \"SQL\" || persistence == \"SQL\")"
},
"ImplicitUsings": {
"type": "computed",
"value": "(framework != \"net472\" && framework != \"net48\")"
}
},
"sources": [
Expand Down
5 changes: 4 additions & 1 deletion src/ParticularTemplates/NServiceBusEndpoint/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#if (!ImplicitUsings)
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
#endif
#if (persistence == "CosmosDB")
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Cosmos.Fluent;
Expand All @@ -11,7 +12,9 @@
#endif
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
#if (!ImplicitUsings)
using NServiceBus;
#endif
#if (persistence == "CosmosDB")
using NServiceBus.Persistence.CosmosDB;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>TARGET_FRAMEWORK</TargetFramework>
<ImplicitUsings Condition="'$(ImplicitUsings)' == 'true'">true</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/ParticularTemplates/Saga/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"replaces": "NamespaceName",
"defaultValue": "Handlers"
},
"ImplicitUsings": {
"type": "bind",
"binding": "msbuild:ImplicitUsings",
"replaces": "ImplicitUsingsValue"
bording marked this conversation as resolved.
Show resolved Hide resolved
},
"messagetype1": {
"type": "parameter",
"description": "The first message type that will be handled by the saga.",
Expand Down
6 changes: 5 additions & 1 deletion src/ParticularTemplates/Saga/SagaName.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#if (!ImplicitUsings)
using System;
using System.Threading.Tasks;
#endif
using Microsoft.Extensions.Logging;
#if (!ImplicitUsings)
using NServiceBus;
using System.Threading.Tasks;
#endif

namespace NamespaceName
{
Expand Down
147 changes: 0 additions & 147 deletions src/Tests/ApprovalFiles/TemplateTests.Handler.approved.txt

This file was deleted.

59 changes: 59 additions & 0 deletions src/Tests/ApprovalFiles/TemplateTests.Handler.default.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---------------------------------------------------------------
HandlerDefault.cs
---------------------------------------------------------------
using Microsoft.Extensions.Logging;

namespace HandlerDefault
{
public class HandlerDefault : IHandleMessages<TestMessage>
{
private readonly ILogger log;

public HandlerDefault(ILogger<HandlerDefault> log)
{
this.log = log;
}

public async Task Handle(TestMessage message, IMessageHandlerContext context)
{
// Business logic here

// Sending commands: https://docs.particular.net/nservicebus/messaging/send-a-message#inside-the-incoming-message-processing-pipeline
// await context.Send(...);

// Publishing events https://docs.particular.net/nservicebus/messaging/publish-subscribe/publish-handle-event
// await context.Publish(...);
}
}
}

---------------------------------------------------------------
HandlerDefault.csproj
---------------------------------------------------------------
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="(VERSION)" />
<PackageReference Include="NServiceBus" Version="(VERSION)" />
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="(VERSION)" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="(VERSION)" />
</ItemGroup>

</Project>
---------------------------------------------------------------
Messages.cs
---------------------------------------------------------------

using NServiceBus;

public class TestMessage : ICommand { }
---------------------------------------------------------------
Program.cs
---------------------------------------------------------------
Contents ignored by test
61 changes: 61 additions & 0 deletions src/Tests/ApprovalFiles/TemplateTests.Handler.net48.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---------------------------------------------------------------
Handlernet48.cs
---------------------------------------------------------------
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NServiceBus;

namespace Handlernet48
{
public class Handlernet48 : IHandleMessages<TestMessage>
{
private readonly ILogger log;

public Handlernet48(ILogger<Handlernet48> log)
{
this.log = log;
}

public async Task Handle(TestMessage message, IMessageHandlerContext context)
{
// Business logic here

// Sending commands: https://docs.particular.net/nservicebus/messaging/send-a-message#inside-the-incoming-message-processing-pipeline
// await context.Send(...);

// Publishing events https://docs.particular.net/nservicebus/messaging/publish-subscribe/publish-handle-event
// await context.Publish(...);
}
}
}

---------------------------------------------------------------
Handlernet48.csproj
---------------------------------------------------------------
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="(VERSION)" />
<PackageReference Include="NServiceBus" Version="(VERSION)" />
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="(VERSION)" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="(VERSION)" />
</ItemGroup>

</Project>
---------------------------------------------------------------
Messages.cs
---------------------------------------------------------------

using NServiceBus;

public class TestMessage : ICommand { }
---------------------------------------------------------------
Program.cs
---------------------------------------------------------------
Contents ignored by test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ NServiceBusEndpoint.csproj
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,13 +20,8 @@ NServiceBusEndpoint.csproj
---------------------------------------------------------------
Program.cs
---------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NServiceBus;

namespace NServiceBusEndpoint
{
Expand Down