This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddSingleton<ISingletonOperation, SingletonOperation>(); | |
services.AddTransient<ITransientOperation, TransientOperation>(); | |
services.AddScoped<IScopedOperation, ScopedOperation>(); | |
services.AddTransient<IMyService, MyService>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly ISingletonOperation _singletonOperation; | |
private readonly IScopedOperation _scopedOperation; | |
private readonly ITransientOperation _transientOperation; | |
private readonly IMyService _myService; | |
private readonly ILogger<HomeController> _logger; | |
public HomeController | |
( | |
ILogger<HomeController> logger, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IMyService | |
{ | |
} | |
public class MyService : IMyService | |
{ | |
private readonly ISingletonOperation _singletonOperation; | |
private readonly ITransientOperation _transientOperation; | |
private readonly IScopedOperation _scopedOperation; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IScopedOperation : IOperation | |
{ | |
} | |
public class ScopedOperation : IScopedOperation | |
{ | |
public Guid Id { get; } | |
public ScopedOperation() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IScopedOperation : IOperation | |
{ | |
} | |
public class ScopedOperation : IScopedOperation | |
{ | |
public Guid Id { get; } | |
public ScopedOperation() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ITransientOperation : IOperation | |
{ | |
} | |
public class TransientOperation : ITransientOperation | |
{ | |
public Guid Id { get; } | |
public TransientOperation() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISingletonOperation : IOperation | |
{ | |
} | |
public class SingletonOperation : ISingletonOperation | |
{ | |
public Guid Id { get; } | |
public SingletonOperation() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IOperation | |
{ | |
Guid Id { get; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bar = new Bar(); | |
var foo = new Foo(bar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bar : IBar { | |
// ... | |
}class Foo { | |
private readonly IBar _bar; | |
public Foo(IBar bar) { | |
_bar = bar; | |
} | |
} |
NewerOlder