Skip to content

Commit

Permalink
Merge branch 'release/3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
MvRens committed Jan 24, 2023
2 parents 1f70b2f + 8675ab3 commit 67031b0
Show file tree
Hide file tree
Showing 156 changed files with 2,571 additions and 1,245 deletions.
13 changes: 6 additions & 7 deletions Examples/01-PublishSubscribe/01-PublishSubscribe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_01_PublishSubscribe</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.2.0" />
<PackageReference Include="Castle.Windsor" Version="5.1.1" />
<PackageReference Include="Ninject" Version="3.3.4" />
<PackageReference Include="SimpleInjector" Version="5.3.0" />
<PackageReference Include="Unity" Version="5.11.10" />
<PackageReference Include="Autofac" Version="6.5.0" />
<PackageReference Include="Castle.Windsor" Version="5.1.2" />
<PackageReference Include="Ninject" Version="3.3.6" />
<PackageReference Include="SimpleInjector" Version="5.4.1" />
</ItemGroup>

<ItemGroup>
Expand All @@ -20,7 +20,6 @@
<ProjectReference Include="..\..\Tapeti.DataAnnotations\Tapeti.DataAnnotations.csproj" />
<ProjectReference Include="..\..\Tapeti.Ninject\Tapeti.Ninject.csproj" />
<ProjectReference Include="..\..\Tapeti.SimpleInjector\Tapeti.SimpleInjector.csproj" />
<ProjectReference Include="..\..\Tapeti.UnityContainer\Tapeti.UnityContainer.csproj" />
<ProjectReference Include="..\..\Tapeti\Tapeti.csproj" />
<ProjectReference Include="..\ExampleLib\ExampleLib.csproj" />
<ProjectReference Include="..\Messaging.TapetiExample\Messaging.TapetiExample.csproj" />
Expand Down
49 changes: 17 additions & 32 deletions Examples/01-PublishSubscribe/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using Tapeti.Default;
using Tapeti.Ninject;
using Tapeti.SimpleInjector;
using Tapeti.UnityContainer;
using Unity;
using Container = SimpleInjector.Container;

// ReSharper disable UnusedMember.Global
Expand All @@ -23,14 +21,13 @@ namespace _01_PublishSubscribe
{
public class Program
{
public static void Main(string[] args)
public static void Main()
{
var dependencyResolver = GetSimpleInjectorDependencyResolver();

// or use your IoC container of choice:
//var dependencyResolver = GetAutofacDependencyResolver();
//var dependencyResolver = GetCastleWindsorDependencyResolver();
//var dependencyResolver = GetUnityDependencyResolver();
//var dependencyResolver = GetNinjectDependencyResolver();

// This helper is used because this example is not run as a service. You do not
Expand All @@ -47,7 +44,7 @@ internal static async Task MainAsync(IDependencyResolver dependencyResolver, Fun
.RegisterAllControllers()
.Build();

using (var connection = new TapetiConnection(config)
await using var connection = new TapetiConnection(config)
{
// Params is optional if you want to use the defaults, but we'll set it
// explicitly for this example
Expand All @@ -63,28 +60,27 @@ internal static async Task MainAsync(IDependencyResolver dependencyResolver, Fun
{ "example", "01 - Publish Subscribe" }
}
}
})
{
// IoC containers that separate the builder from the resolver (Autofac) must be built after
// creating a TapetConnection, as it modifies the container by injecting IPublisher.
(dependencyResolver as AutofacDependencyResolver)?.Build();
};

// IoC containers that separate the builder from the resolver (Autofac) must be built after
// creating a TapetConnection, as it modifies the container by injecting IPublisher.
(dependencyResolver as AutofacDependencyResolver)?.Build();


// Create the queues and start consuming immediately.
// If you need to do some processing before processing messages, but after the
// queues have initialized, pass false as the startConsuming parameter and store
// the returned ISubscriber. Then call Resume on it later.
await connection.Subscribe();
// Create the queues and start consuming immediately.
// If you need to do some processing before processing messages, but after the
// queues have initialized, pass false as the startConsuming parameter and store
// the returned ISubscriber. Then call Resume on it later.
await connection.Subscribe();


// We could get an IPublisher from the container directly, but since you'll usually use
// it as an injected constructor parameter this shows
await dependencyResolver.Resolve<ExamplePublisher>().SendTestMessage();
// We could get an IPublisher from the container directly, but since you'll usually use
// it as an injected constructor parameter this shows
await dependencyResolver.Resolve<ExamplePublisher>().SendTestMessage();


// Wait for the controller to signal that the message has been received
await waitForDone();
}
// Wait for the controller to signal that the message has been received
await waitForDone();
}


Expand Down Expand Up @@ -132,17 +128,6 @@ internal static IDependencyContainer GetCastleWindsorDependencyResolver()
}


internal static IDependencyContainer GetUnityDependencyResolver()
{
var container = new UnityContainer();

container.RegisterType<ILogger, ConsoleLogger>();
container.RegisterType<ExamplePublisher>();

return new UnityDependencyResolver(container);
}


internal static IDependencyContainer GetNinjectDependencyResolver()
{
var kernel = new StandardKernel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_02_DeclareDurableQueues</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SimpleInjector" Version="5.3.0" />
<PackageReference Include="SimpleInjector" Version="5.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
23 changes: 11 additions & 12 deletions Examples/02-DeclareDurableQueues/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace _02_DeclareDurableQueues
{
public class Program
{
public static void Main(string[] args)
public static void Main()
{
var container = new Container();
var dependencyResolver = new SimpleInjectorDependencyResolver(container);
Expand All @@ -30,19 +30,18 @@ internal static async Task MainAsync(IDependencyResolver dependencyResolver, Fun
.EnableDeclareDurableQueues()
.Build();

using (var connection = new TapetiConnection(config))
{
// This creates or updates the durable queue
await connection.Subscribe();
await using var connection = new TapetiConnection(config);

// This creates or updates the durable queue
await connection.Subscribe();

await dependencyResolver.Resolve<IPublisher>().Publish(new PublishSubscribeMessage
{
Greeting = "Hello durable queue!"
});
await dependencyResolver.Resolve<IPublisher>().Publish(new PublishSubscribeMessage
{
Greeting = "Hello durable queue!"
});

// Wait for the controller to signal that the message has been received
await waitForDone();
}
// Wait for the controller to signal that the message has been received
await waitForDone();
}
}
}
5 changes: 3 additions & 2 deletions Examples/03-FlowRequestResponse/03-FlowRequestResponse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_03_FlowRequestResponse</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SimpleInjector" Version="5.3.0" />
<PackageReference Include="SimpleInjector" Version="5.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Examples/03-FlowRequestResponse/ParallelFlowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class ParallelFlowController
private readonly IFlowProvider flowProvider;
private readonly IExampleState exampleState;

public string FirstQuote;
public string SecondQuote;
public string ThirdQuote;
public string? FirstQuote;
public string? SecondQuote;
public string? ThirdQuote;


public ParallelFlowController(IFlowProvider flowProvider, IExampleState exampleState)
Expand Down Expand Up @@ -56,7 +56,7 @@ public void HandleFirstQuoteResponse(QuoteResponseMessage message)


[Continuation]
public async Task HandleSecondQuoteResponse(QuoteResponseMessage message, IFlowParallelRequest parallelRequest)
public async ValueTask HandleSecondQuoteResponse(QuoteResponseMessage message, IFlowParallelRequest parallelRequest)
{
Console.WriteLine("[ParallelFlowController] Second quote response received");
SecondQuote = message.Quote;
Expand Down
39 changes: 19 additions & 20 deletions Examples/03-FlowRequestResponse/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace _03_FlowRequestResponse
{
public class Program
{
public static void Main(string[] args)
public static void Main()
{
var container = new Container();
var dependencyResolver = new SimpleInjectorDependencyResolver(container);
Expand All @@ -33,34 +33,33 @@ internal static async Task MainAsync(IDependencyResolver dependencyResolver, Fun
.Build();


using (var connection = new TapetiConnection(config))
{
// Must be called before using any flow. When using a persistent repository like the
// SQL server implementation, you can run any required update scripts (for example, using DbUp)
// before calling this Load method.
// Call after creating the TapetiConnection, as it modifies the container to inject IPublisher.
await dependencyResolver.Resolve<IFlowStore>().Load();
await using var connection = new TapetiConnection(config);

// Must be called before using any flow. When using a persistent repository like the
// SQL server implementation, you can run any required update scripts (for example, using DbUp)
// before calling this Load method.
// Call after creating the TapetiConnection, as it modifies the container to inject IPublisher.
await dependencyResolver.Resolve<IFlowStore>().Load();


await connection.Subscribe();
await connection.Subscribe();


var flowStarter = dependencyResolver.Resolve<IFlowStarter>();
var flowStarter = dependencyResolver.Resolve<IFlowStarter>();

var startData = new SimpleFlowController.StartData
{
RequestStartTime = DateTime.Now,
Amount = 1
};
var startData = new SimpleFlowController.StartData
{
RequestStartTime = DateTime.Now,
Amount = 1
};


await flowStarter.Start<SimpleFlowController, SimpleFlowController.StartData>(c => c.StartFlow, startData);
await flowStarter.Start<ParallelFlowController>(c => c.StartFlow);
await flowStarter.Start<SimpleFlowController, SimpleFlowController.StartData>(c => c.StartFlow, startData);
await flowStarter.Start<ParallelFlowController>(c => c.StartFlow);


// Wait for the controller to signal that the message has been received
await waitForDone();
}
// Wait for the controller to signal that the message has been received
await waitForDone();
}
}
}
23 changes: 7 additions & 16 deletions Examples/03-FlowRequestResponse/ReceivingMessageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@ namespace _03_FlowRequestResponse
public class ReceivingMessageController
{
// No publisher required, responses can simply be returned
public async Task<QuoteResponseMessage> HandleQuoteRequest(QuoteRequestMessage message)
public static async Task<QuoteResponseMessage> HandleQuoteRequest(QuoteRequestMessage message)
{
string quote;

switch (message.Amount)
var quote = message.Amount switch
{
case 1:
1 =>
// Well, they asked for it... :-)
quote = "'";
break;

case 2:
quote = "\"";
break;

default:
quote = new string('\'', message.Amount);
break;
}
"'",
2 => "\"",
_ => new string('\'', message.Amount)
};

// Just gonna let them wait for a bit, to demonstrate async message handlers
await Task.Delay(1000);
Expand Down
5 changes: 3 additions & 2 deletions Examples/04-Transient/04-Transient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_04_Transient</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SimpleInjector" Version="5.3.0" />
<PackageReference Include="SimpleInjector" Version="5.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 9 additions & 11 deletions Examples/04-Transient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace _04_Transient
{
public class Program
{
public static void Main(string[] args)
public static void Main()
{
var container = new Container();
var dependencyResolver = new SimpleInjectorDependencyResolver(container);
Expand All @@ -34,22 +34,20 @@ internal static async Task MainAsync(IDependencyResolver dependencyResolver, Fun
.Build();


using (var connection = new TapetiConnection(config))
{
await connection.Subscribe();
await using var connection = new TapetiConnection(config);
await connection.Subscribe();


Console.WriteLine("Sending request...");
Console.WriteLine("Sending request...");

var transientPublisher = dependencyResolver.Resolve<ITransientPublisher>();
var response = await transientPublisher.RequestResponse<LoggedInUsersRequestMessage, LoggedInUsersResponseMessage>(
new LoggedInUsersRequestMessage());
var transientPublisher = dependencyResolver.Resolve<ITransientPublisher>();
var response = await transientPublisher.RequestResponse<LoggedInUsersRequestMessage, LoggedInUsersResponseMessage>(
new LoggedInUsersRequestMessage());

Console.WriteLine("Response: " + response.Count);
Console.WriteLine("Response: " + response.Count);


// Unlike the other example, there is no need to call waitForDone, once we're here the response has been handled.
}
// Unlike the other example, there is no need to call waitForDone, once we're here the response has been handled.
}
}
}
5 changes: 3 additions & 2 deletions Examples/05-SpeedTest/05-SpeedTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_05_SpeedTest</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SimpleInjector" Version="5.3.0" />
<PackageReference Include="SimpleInjector" Version="5.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 67031b0

Please sign in to comment.