C# 如何将服务添加到AccountController以实现Asp身份和工作单元模式

C# 如何将服务添加到AccountController以实现Asp身份和工作单元模式,c#,asp.net,asp.net-mvc,entity-framework,asp.net-identity,C#,Asp.net,Asp.net Mvc,Entity Framework,Asp.net Identity,我遇到了一个问题,即在AccountController中注入服务模式以实现ASP.Net标识。这是我的密码: 客户控制员构造函数 public class AccountController : Controller { private readonly IMyProfileService _profileService; private readonly IUnitOfWorkAsync _unitOfWorkAsync; private ApplicationUse

我遇到了一个问题,即在AccountController中注入服务模式以实现ASP.Net标识。这是我的密码:

客户控制员构造函数

public class AccountController : Controller
{
    private readonly IMyProfileService _profileService;
    private readonly IUnitOfWorkAsync _unitOfWorkAsync;
    private ApplicationUserManager _userManager;
    public ApplicationUserManager UserManager
    {
        get
        {
            return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
        }
        private set
        {
            _userManager = value;
        }
    }

    private ApplicationSignInManager _signInManager;
    public ApplicationSignInManager SignInManager
    {
        get
        {
            return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
        }
        private set { _signInManager = value; }
    }

    private ApplicationRoleManager _roleManager;
    public ApplicationRoleManager RoleManager
    {
        get
        {
            return _roleManager ?? HttpContext.GetOwinContext().Get<ApplicationRoleManager>();
        }
        private set
        {
            _roleManager = value;
        }
    }
    public AccountController()
    {      
    }

    public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager, 
        ApplicationRoleManager roleManager,IMyProfileService profileService ,IUnitOfWorkAsync unitOfWorkAsync )
    {        
        UserManager = userManager;
        SignInManager = signInManager;
        RoleManager = roleManager;
        _profileService = profileService;
        _unitOfWorkAsync = unitOfWorkAsync;
    }
它给了我Null Ref异常。。顺便说一句,这是我的国际奥委会关于团结的决议:

   container
            .RegisterType<IDataContextAsync, NovusTNContext>(new PerRequestLifetimeManager())
            .RegisterType<IUnitOfWorkAsync, UnitOfWork>(new PerRequestLifetimeManager())
            .RegisterType<IRepositoryAsync<Education>, Repository<Education>>()
            .RegisterType<IRepositoryAsync<Profile>, Repository<Profile>>()
             .RegisterType<IRepositoryAsync<Job>, Repository<Job>>()
            .RegisterType<IEducationService, EducationService>()
            .RegisterType<IJobService, JobService>()
            .RegisterType<IMyProfileService, MyProfileService>()

            //*****************Membership Authentication Registration***************//

            .RegisterType<DbContext, MembershipContext>(new HierarchicalLifetimeManager())
            .RegisterType<UserManager<ApplicationUser>>(new HierarchicalLifetimeManager())
            .RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new HierarchicalLifetimeManager())
            .RegisterType<AccountController>(new InjectionConstructor());
容器
.RegisterType(新PerRequestLifetimeManager())
.RegisterType(新PerRequestLifetimeManager())
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
.RegisterType()
//*****************会员身份验证注册***************//
.RegisterType(新层次结构CallifeTimeManager())
.RegisterType(新层次结构CallifeTimeManager())
.RegisterType(新层次结构CallifeTimeManager())
.RegisterType(新注入构造函数());
我使用它的目的是当用户注册或登录时,我可以使用配置文件服务在注册时创建一个新的配置文件,并在登录时调出配置文件。任何帮助都是有价值的。短暂性脑缺血发作

   container
            .RegisterType<IDataContextAsync, NovusTNContext>(new PerRequestLifetimeManager())
            .RegisterType<IUnitOfWorkAsync, UnitOfWork>(new PerRequestLifetimeManager())
            .RegisterType<IRepositoryAsync<Education>, Repository<Education>>()
            .RegisterType<IRepositoryAsync<Profile>, Repository<Profile>>()
             .RegisterType<IRepositoryAsync<Job>, Repository<Job>>()
            .RegisterType<IEducationService, EducationService>()
            .RegisterType<IJobService, JobService>()
            .RegisterType<IMyProfileService, MyProfileService>()

            //*****************Membership Authentication Registration***************//

            .RegisterType<DbContext, MembershipContext>(new HierarchicalLifetimeManager())
            .RegisterType<UserManager<ApplicationUser>>(new HierarchicalLifetimeManager())
            .RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new HierarchicalLifetimeManager())
            .RegisterType<AccountController>(new InjectionConstructor());