I have been attempting to get Lamar working for our dependency injection, but my lack of experience doing so has been causing me some grief.
I have a simple dummy controller:
[Route("[controller]")]
public class TestController : Controller
{
[HttpGet]
public int GetRandom()
{
TestService service = new TestService();
int value = service.GetRandomNumber();
return value;
}
}
Inside of TestService is an interface'd repository, where I would like the DI to apply to.
I've added UseLamar to my Program.cs, and my startup.cs looks like this:
public void ConfigureContainer(ServiceRegistry services)
{
services.AddMvc();
services.Scan(s =>
{
s.Assembly("Test.Components");
s.WithDefaultConventions();
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.Run(async (context) =>
{
await context.Response.WriteAsync("Invalid");
});
app.UseMvc();
}
From reading the documentation I believe that Lamar should automatically map my Interface to my type, as they have the same name (IRepository -> Repository), though thats not what I am seeing.
I'm very sure I've missed something, but I've been over the documentation and have been attempting to google around for real examples to no avail. Is there some lines I am missing in Startup.cs? Does my Service need a constructor to set the Repository?