Skip to content

Commit f812849

Browse files
namespaces for types, move global usings to usings.cs
1 parent 765ef1f commit f812849

35 files changed

+101
-43
lines changed

2_Libs/DependencyInjectionAndConfiguration/DI/DIWithConfiguration/GreetingService.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class GreetingService : IGreetingService
1+
namespace DISample;
2+
3+
public class GreetingService : IGreetingService
24
{
35
public GreetingService(IOptions<GreetingServiceOptions> options)
46
{

2_Libs/DependencyInjectionAndConfiguration/DI/DIWithConfiguration/GreetingServiceExtensions.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public static class GreetingServiceExtensions
1+
namespace DISample;
2+
3+
public static class GreetingServiceExtensions
24
{
35
public static IServiceCollection AddGreetingService(this IServiceCollection services, IConfiguration config)
46
{
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class GreetingServiceOptions
1+
namespace DISample;
2+
3+
public class GreetingServiceOptions
24
{
35
public string? From { get; set; }
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/DIWithConfiguration/HomeController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class HomeController
1+
namespace DISample;
2+
3+
public class HomeController
24
{
35
private readonly IGreetingService _greetingService;
46
public HomeController(IGreetingService greetingService)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public interface IGreetingService
1+
namespace DISample;
2+
3+
public interface IGreetingService
24
{
35
string Greet(string name);
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/DIWithConfiguration/Program.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
global using Microsoft.Extensions.Configuration;
2-
global using Microsoft.Extensions.DependencyInjection;
3-
global using Microsoft.Extensions.Hosting;
4-
global using Microsoft.Extensions.Options;
5-
6-
var builder = new HostApplicationBuilder(args);
1+
var builder = new HostApplicationBuilder(args);
72
builder.Services.AddGreetingService(builder.Configuration.GetSection("GreetingService"));
83
builder.Services.AddSingleton<IGreetingService, GreetingService>();
94
builder.Services.AddTransient<HomeController>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
global using Microsoft.Extensions.Configuration;
2+
global using Microsoft.Extensions.DependencyInjection;
3+
global using Microsoft.Extensions.Hosting;
4+
global using Microsoft.Extensions.Options;
5+
6+
global using DISample;

2_Libs/DependencyInjectionAndConfiguration/DI/DIWithOptions/GreetingService.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class GreetingService : IGreetingService
1+
namespace DISample;
2+
3+
public class GreetingService : IGreetingService
24
{
35
public GreetingService(IOptions<GreetingServiceOptions> options) =>
46
_from = options.Value.From;

2_Libs/DependencyInjectionAndConfiguration/DI/DIWithOptions/GreetingServiceExtensions.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public static class GreetingServiceExtensions
1+
namespace DISample;
2+
3+
public static class GreetingServiceExtensions
24
{
35
public static IServiceCollection AddGreetingService(this IServiceCollection collection,
46
Action<GreetingServiceOptions> setupAction)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class GreetingServiceOptions
1+
namespace DISample;
2+
3+
public class GreetingServiceOptions
24
{
35
public string? From { get; set; }
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/DIWithOptions/HomeController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class HomeController
1+
namespace DISample;
2+
3+
public class HomeController
24
{
35
private readonly IGreetingService _greetingService;
46
public HomeController(IGreetingService greetingService)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public interface IGreetingService
1+
namespace DISample;
2+
3+
public interface IGreetingService
24
{
35
string Greet(string name);
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/DIWithOptions/Program.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
global using Microsoft.Extensions.DependencyInjection;
2-
global using Microsoft.Extensions.Hosting;
3-
global using Microsoft.Extensions.Options;
4-
5-
var builder = new HostApplicationBuilder(args);
1+
var builder = new HostApplicationBuilder(args);
62
builder.Services.AddGreetingService(options =>
73
{
84
options.From = "Christian";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
global using Microsoft.Extensions.DependencyInjection;
2+
global using Microsoft.Extensions.Hosting;
3+
global using Microsoft.Extensions.Options;
4+
5+
global using DISample;

2_Libs/DependencyInjectionAndConfiguration/DI/ServicesLifetime/ControllerX.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public sealed class ControllerX : IDisposable
1+
namespace DISample;
2+
3+
public sealed class ControllerX : IDisposable
24
{
35
private readonly IServiceA _serviceA;
46
private readonly IServiceB _serviceB;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public interface INumberService
1+
namespace DISample;
2+
3+
public interface INumberService
24
{
35
int GetNumber();
46
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public interface IServiceA
1+
namespace DISample;
2+
3+
public interface IServiceA
24
{
35
void A();
46
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public interface IServiceB
1+
namespace DISample;
2+
3+
public interface IServiceB
24
{
35
void B();
46
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public interface IServiceC
1+
namespace DISample;
2+
3+
public interface IServiceC
24
{
35
void C();
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/ServicesLifetime/NumberService.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class NumberService : INumberService
1+
namespace DISample;
2+
3+
public class NumberService : INumberService
24
{
35
private int _number = 0;
46
public int GetNumber() => Interlocked.Increment(ref _number);

2_Libs/DependencyInjectionAndConfiguration/DI/ServicesLifetime/Program.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
global using Microsoft.Extensions.DependencyInjection;
2-
global using Microsoft.Extensions.Hosting;
3-
global using Microsoft.Extensions.Options;
1+

42
class Program
53
{
64
static void Main(string mode)

2_Libs/DependencyInjectionAndConfiguration/DI/ServicesLifetime/ServiceA.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class ConfigurationA
1+
namespace DISample;
2+
3+
public class ConfigurationA
24
{
35
public string? Mode { get; set; }
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/ServicesLifetime/ServiceB.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class ConfigurationB
1+
namespace DISample;
2+
3+
public class ConfigurationB
24
{
35
public string? Mode { get; set; }
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/ServicesLifetime/ServiceC.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class ConfigurationC
1+
namespace DISample;
2+
3+
public class ConfigurationC
24
{
35
public string? Mode { get; set; }
46
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
global using Microsoft.Extensions.DependencyInjection;
2+
global using Microsoft.Extensions.Hosting;
3+
global using Microsoft.Extensions.Options;
4+
5+
global using DISample;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class GreetingService : IGreetingService
1+
namespace DISample;
2+
3+
public class GreetingService : IGreetingService
24
{
35
public string Greet(string name) => $"Hello, {name}";
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/WithDIContainer/HomeController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class HomeController
1+
namespace DISample;
2+
3+
public class HomeController
24
{
35
private readonly IGreetingService _greetingService;
46
public HomeController(IGreetingService greetingService) =>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public interface IGreetingService
1+
namespace DISample;
2+
3+
public interface IGreetingService
24
{
35
string Greet(string name);
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/WithDIContainer/Program.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
global using Microsoft.Extensions.DependencyInjection;
2-
3-
using ServiceProvider container = GetServiceProvider();
1+
using ServiceProvider container = GetServiceProvider();
42
var controller = container.GetRequiredService<HomeController>();
53
string result = controller.Hello("Stephanie");
64
Console.WriteLine(result);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global using Microsoft.Extensions.DependencyInjection;
2+
3+
global using DISample;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class GreetingService : IGreetingService
1+
namespace DISample;
2+
3+
public class GreetingService : IGreetingService
24
{
35
public string Greet(string name) => $"Hello, {name}";
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/WithHost/HomeController.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class HomeController
1+
namespace DISample;
2+
3+
public class HomeController
24
{
35
private readonly IGreetingService _greetingService;
46
public HomeController(IGreetingService greetingService)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public interface IGreetingService
1+
namespace DISample;
2+
3+
public interface IGreetingService
24
{
35
string Greet(string name);
46
}

2_Libs/DependencyInjectionAndConfiguration/DI/WithHost/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var builder = new HostApplicationBuilder(args);
1+
HostApplicationBuilder builder = new(args);
22
builder.Services.AddSingleton<IGreetingService, GreetingService>();
33
builder.Services.AddTransient<HomeController>();
44
using var host = builder.Build();
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
global using Microsoft.Extensions.DependencyInjection;
22
global using Microsoft.Extensions.Hosting;
3+
4+
global using DISample;

0 commit comments

Comments
 (0)