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

Minor improvements to dependency injection example #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace Injection.Infrastructure;

public sealed class TypeRegistrar : ITypeRegistrar
public sealed class MyTypeRegistrar : ITypeRegistrar
{
private readonly IServiceCollection _builder;

public TypeRegistrar(IServiceCollection builder)
public MyTypeRegistrar(IServiceCollection builder)
{
_builder = builder;
}

public ITypeResolver Build()
{
return new TypeResolver(_builder.BuildServiceProvider());
return new MyTypeResolver(_builder.BuildServiceProvider());
}

public void Register(Type service, Type implementation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace Injection.Infrastructure;

public sealed class TypeResolver : ITypeResolver, IDisposable
public sealed class MyTypeResolver : ITypeResolver, IDisposable
{
private readonly IServiceProvider _provider;

public TypeResolver(IServiceProvider provider)
public MyTypeResolver(IServiceProvider provider)
{
_provider = provider ?? throw new ArgumentNullException(nameof(provider));
}
Expand Down
7 changes: 4 additions & 3 deletions examples/Cli/Injection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ public class Program
{
public static int Main(string[] args)
{
// Create a type registrar and register any dependencies.
// A type registrar is an adapter for a DI framework.
var registrations = new ServiceCollection();
registrations.AddSingleton<IGreeter, HelloWorldGreeter>();
var registrar = new TypeRegistrar(registrations);

// Create a type registrar and register any dependencies.
// A type registrar is an adapter for a DI framework.
var registrar = new MyTypeRegistrar(registrations);

// Create a new command app with the registrar
// and run it with the provided arguments.
Expand Down