File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111 "cwd" : " ${workspaceFolder}/src/ConsoleApp" ,
1212 "stopAtEntry" : false ,
1313 "console" : " internalConsole"
14+ },
15+ {
16+ "name" : " Benchmark" ,
17+ "type" : " coreclr" ,
18+ "request" : " launch" ,
19+ "preLaunchTask" : " build:release" ,
20+ "program" : " ${workspaceFolder}/src/ConsoleApp/bin/Release/net9.0/ConsoleApp.dll" ,
21+ "args" : [ " --benchmark" , " true" ],
22+ "cwd" : " ${workspaceFolder}/src/ConsoleApp" ,
23+ "stopAtEntry" : false ,
24+ "console" : " internalConsole"
1425 }
1526 ]
1627}
Original file line number Diff line number Diff line change 1212 " /consoleloggerparameters:NoSummary;ForceNoAlign"
1313 ],
1414 "problemMatcher" : " $msCompile"
15+ },
16+ {
17+ "label" : " build:release" ,
18+ "command" : " dotnet" ,
19+ "type" : " process" ,
20+ "args" : [
21+ " build" ,
22+ " ${workspaceFolder}/src/dotnet-basic-console.sln" ,
23+ " -c" ,
24+ " Release" ,
25+ " /property:GenerateFullPaths=true" ,
26+ " /consoleloggerparameters:NoSummary;ForceNoAlign"
27+ ],
28+ "problemMatcher" : " $msCompile"
1529 }
1630 ]
1731}
Original file line number Diff line number Diff line change 1+ using BenchmarkDotNet . Attributes ;
2+ using ConsoleApp . Models . Configuration ;
3+ using ConsoleApp . Services ;
4+ using Microsoft . Extensions . Options ;
5+
6+ namespace ConsoleApp ;
7+
8+ public class BenchmarkService (
9+ IDemoService demoService ,
10+ IOptions < ConsoleAppSettings > options )
11+ {
12+ private readonly IDemoService _demoService = demoService ;
13+ private readonly IOptions < ConsoleAppSettings > _options = options ;
14+
15+ [ GlobalSetup ]
16+ public void Setup ( )
17+ {
18+ // initialize things in class if needed
19+ }
20+
21+ [ Benchmark ]
22+ public void WriteWelcomeMessage ( )
23+ {
24+ for ( var i = 0 ; i < 100 ; i ++ )
25+ {
26+ _demoService . WriteWelcomeMessage ( ) ;
27+ }
28+ }
29+ }
Original file line number Diff line number Diff line change 99using Microsoft . Identity . Client ;
1010using Serilog ;
1111using OpenTelemetry . Logs ;
12+ using BenchmarkDotNet . Running ;
1213
1314var builder = Host . CreateDefaultBuilder ( args )
1415 . ConfigureAppConfiguration ( ( hostContext , configBuilder ) =>
5455
5556using var host = builder . Build ( ) ;
5657
57- await host . RunAsync ( ) ;
58+ var configuration = host . Services . GetRequiredService < IConfiguration > ( ) ;
59+
60+ if ( configuration . GetValue < bool ? > ( "benchmark" ) == true )
61+ {
62+ BenchmarkRunner . Run < BenchmarkService > ( ) ;
63+ }
64+ else
65+ {
66+ await host . RunAsync ( ) ;
67+ }
Original file line number Diff line number Diff line change 44
55namespace ConsoleApp . Services ;
66
7- internal interface IClientCredentialService
7+ public interface IClientCredentialService
88{
99 Task < AuthenticationResult ? > GetAuthenticationResult ( IEnumerable < string > ? scopes = null ) ;
1010 Task < string > GetAccessToken ( IEnumerable < string > ? scopes = null ) ;
1111}
1212
13- internal class ClientCredentialService ( ILogger < ClientCredentialService > logger ,
13+ public class ClientCredentialService ( ILogger < ClientCredentialService > logger ,
1414 IOptions < ConfidentialClientApplicationOptions > confidentialClientApplicationOptions ) : IClientCredentialService
1515{
1616 private readonly ILogger < ClientCredentialService > _logger = logger ;
Original file line number Diff line number Diff line change 66
77namespace ConsoleApp . Services ;
88
9- internal interface IDemoService
9+ public interface IDemoService
1010{
1111 void WriteWelcomeMessage ( ) ;
1212 Task < string > MakeGraphApiCall ( ) ;
1313}
1414
15- internal class DemoService ( ILogger < DemoService > logger ,
15+ public class DemoService ( ILogger < DemoService > logger ,
1616 IClientCredentialService clientCredentialService ,
1717 IOptions < ConsoleAppSettings > consoleAppSettings ,
1818 IHttpClientFactory httpClientFactory ) : IDemoService
You can’t perform that action at this time.
0 commit comments