I'm using structure map with the AspNet Core 1.0 RTM. It appears they have removed using the FromServices attribute on properties. This breaks the code below because I am now unable to inject the ClaimsPrincipal. I'm not sure how to get the DI system to pickup this property. Do I need to create a custom InputFormatter or something else. That seems like a lot of work to get this working again.
Startup.cs
public class Startup {
public IServiceProvider ConfigureServices(IServiceCollection services) {
var container = new Container();
container.Configure(i => {
i.For<IHttpContextAccessor>()
.Use(new HttpContextAccessor());
i.For<ClaimsPrincipal>()
.Use(x => x.GetInstance<IHttpContextAccessor>().HttpContext.User);
});
container.Populate(services);
return container.GetInstance<IServiceProvider>();
}
}
Model.cs
public class Model {
//[FromServices] <-- worked in RC1
public ClaimsPrincipal Principal { get; set; }
public string Value => Principal.Identity.Name;
}
TestController.cs
public class TestController : Controller {
public IActionResult Test(Model model){
return Ok();
}
}