benfoster / NakedIdentity

ASP.NET Identity, stripped bare.
MIT License
72 stars 37 forks source link

Accessing AppController.CurrentUser from child controller constructor raises StructureMap.Building.StructureMapBuildException #2

Open Mimisss opened 7 years ago

Mimisss commented 7 years ago

Based on your post: http://benfoster.io/blog/aspnet-identity-stripped-bare-mvc-part-1

The following raises StructureMap.Building.StructureMapBuildException with inner exception Object reference not set to an instance of an object. Debugging reveals this.User in 'AppController' is null:

public class HomeController : AppController
{
        private IMyService service;

        public HomeController(IMyService service)
        {
            this.service.User = this.CurrentUser;
        }
}

Any idea why?

faridskyman commented 5 years ago

part-1 actually its ok. altho the blog summarizes alot of part, i got through getting it to work by also referring to https://github.com/benfoster/NakedIdentity/commit/ce11643729f9929040b4979cc76e14a3908f8461#diff-3e72cd4f925f1beaebdbac61f9b3dea3