-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
193 additions
and
73 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#region Imports | ||
using AutofacExamples.Api.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
#endregion | ||
|
||
namespace AutofacExamples.Api.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class TestController : ControllerBase | ||
{ | ||
#region Members | ||
|
||
private readonly IService _service; | ||
private readonly ILogger<TestController> _logger; | ||
|
||
#endregion | ||
|
||
#region Ctor | ||
|
||
public TestController(IService service, ILogger<TestController> logger) | ||
{ | ||
_service = service; | ||
_logger = logger; | ||
} | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
[HttpGet] | ||
public IActionResult Get() | ||
{ | ||
var result = _service.Method(0, ""); | ||
return Ok(result); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
39 changes: 0 additions & 39 deletions
39
src/AutofacExamples.Api/Controllers/WeatherForecastController.cs
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#region Imports | ||
using Autofac; | ||
using AutofacExamples.Api.Services; | ||
#endregion | ||
|
||
namespace AutofacExamples.Api.Infrastructure | ||
{ | ||
/// <summary> | ||
/// Autofac module | ||
/// Configure related services that provide a subsystem. | ||
/// Package optional application features as ‘plug-ins’. | ||
/// Register a number of similar services that are often used together. | ||
/// </summary> | ||
public class MyAutofacModule : Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
//builder.RegisterType<MyService>().As<IService>(); | ||
|
||
// Transient | ||
builder.RegisterType<MyService>().As<IService>() | ||
.InstancePerDependency(); | ||
|
||
// Scoped | ||
builder.RegisterType<MyService>().As<IService>() | ||
.InstancePerLifetimeScope(); | ||
|
||
builder.RegisterType<MyService>().As<IService>() | ||
.InstancePerRequest(); | ||
|
||
|
||
// Singleton | ||
builder.RegisterType<MyService>().As<IService>() | ||
.SingleInstance(); | ||
|
||
|
||
|
||
//// Scan an assembly for components | ||
//builder.RegisterAssemblyTypes(typeof(Startup).Assembly) | ||
// .Where(t => t.Name.EndsWith("Service")) | ||
// .AsImplementedInterfaces(); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace AutofacExamples.Api.Services | ||
{ | ||
public interface IService | ||
{ | ||
string Method(int i, string s); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace AutofacExamples.Api.Services | ||
{ | ||
public class MyService : IService | ||
{ | ||
public string Method(int i, string s) | ||
{ | ||
return "My Data"; | ||
} | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.