Skip to content

Commit 8047592

Browse files
author
Roman Alekseev
committed
configuration chaining in demo console app
1 parent 32adb8b commit 8047592

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

src/Profiler.Demo.Stopwatch/ContainerBootstrapper.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Profiler.Demo.Stopwatch/ProfilerConfigurationSettingsExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ namespace Profiler.Demo.Stopwatch
44
{
55
public static class ProfilerConfigurationSettingsExtensions
66
{
7-
public static void UseConsoleTraceWriter(this IProfilerConfiguration settings)
7+
public static IProfilerConfiguration UseConsoleTraceWriter(this IProfilerConfiguration settings)
88
{
99
settings.CreateTraceWriter = () => new ConsoleTraceWriter();
10+
return settings;
1011
}
1112

12-
public static void UseConsoleReportWriter(this IProfilerConfiguration settings)
13+
public static IProfilerConfiguration UseConsoleReportWriter(this IProfilerConfiguration settings)
1314
{
1415
settings.CreateReportWriter = () => new ConsoleReportWriter();
16+
return settings;
1517
}
1618
}
1719
}

src/Profiler.Demo.Stopwatch/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Threading;
5-
using Microsoft.Extensions.DependencyInjection;
65

76
namespace Profiler.Demo.Stopwatch
87
{
98
class Program
109
{
1110
static void Main(string[] args)
1211
{
13-
var serviceProvider = ContainerBootstrapper.Build();
14-
15-
var profile = serviceProvider.GetService<IProfiler>();
12+
var profiler = new ProfilerConfiguration()
13+
.UseStopwatchTimeMeasure()
14+
.UseConsoleTraceWriter()
15+
.UseConsoleReportWriter()
16+
.CreateProfiler();
1617

1718
var threads = new List<Thread>();
1819
for (int i = 0; i < 3; i++)
1920
{
2021
var thread = new Thread(() =>
2122
{
2223
TimeSpan delay = TimeSpan.FromMilliseconds(i * 100);
23-
using (var section = profile.Section("section.{i}.{delay}", i, delay))
24+
using (var section = profiler.Section("section.{i}.{delay}", i, delay))
2425
{
2526
Thread.Sleep(delay);
2627

@@ -43,7 +44,7 @@ static void Main(string[] args)
4344
thread.Join();
4445
}
4546

46-
profile.WriteReport();
47+
profiler.WriteReport();
4748

4849
Console.ReadKey();
4950
}

0 commit comments

Comments
 (0)