0

In my Asp.Net Web API application I am using Simple Injector as IoC container. It's resolving the dependencies of other controllers. But I am having problems with the dependencies of default AccountController.

private static void ConfigureTypes(Container container)
{
    container.Register<Data.Contracts.Repositories.IProfileRepository,
        Data.Repositories.ProfileRepository>(Lifestyle.Transient);
}

public static void Configure()
{
    var container = new Container();
    container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
    ConfigureTypes(container);
    var config = GlobalConfiguration.Configuration;
    container.RegisterWebApiControllers(config);

    container.Verify();
    config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
}

What should I do to resolve the dependencies of AccountController. Here are AccountController's default and parameterized constructors:

public AccountController()
{
}

public AccountController(ApplicationUserManager userManager,
    ISecureDataFormat<AuthenticationTicket> accessTokenFormat)
{
    UserManager = userManager;
    AccessTokenFormat = accessTokenFormat;
}
Steven
  • 166,672
  • 24
  • 332
  • 435
Ali Shahzad
  • 5,163
  • 7
  • 36
  • 64
  • Is the ApplicationUserManager class an interface? If not, create an interface of it and register the type in the ConfigureTypes() method – Marcus Höglund Mar 10 '17 at 06:19
  • AccountController is the absolute crap that is generated for you by a Visual Studio template. It's stuffed with bad practices, SOLID violations and amti-patterns. A great way to teach developers wrong things. Ideally uou should get rid of it or refactor it, but to get your application running, judt remove the overloaded constructor. – Steven Mar 10 '17 at 06:29
  • Many thanks @Steven, I have removed the overloaded constructor and it worked for me. But how can I refactor this? Because in future I have to inject dependencies in AccountController (may be of repository). – Ali Shahzad Mar 10 '17 at 06:37
  • There's an old description on Codeplex about the [Identity Framework template](https://simpleinjector.codeplex.com/discussions/564822) that I think is still relevant. – Steven Mar 10 '17 at 06:42
  • Right, I am checking it. Thanks again. – Ali Shahzad Mar 10 '17 at 06:43
  • Related: https://stackoverflow.com/q/36356431/3294832 – Steven Mar 10 '17 at 09:35
  • Related: https://stackoverflow.com/q/37085776/3294832 – Steven Mar 10 '17 at 09:35
  • Related: https://stackoverflow.com/a/28948205/264697 – Steven Mar 10 '17 at 09:43

0 Answers0