0

I'm applying asp.net identity with repository pattern and having some trouble. In Unity, I see it register as below (it's runned):

container.RegisterType<IUserStore<IdentityUser, Guid>, UserStore>(new TransientLifetimeManager());
container.RegisterType<RoleStore>(new TransientLifetimeManager());

Now I want to register by using Autofac, especial the first register code but I can't find anything about this. If you have another solution for apply asp net identity with repository pattern.

Cyril Durand
  • 15,834
  • 5
  • 54
  • 62
Jen
  • 1
  • 4
  • Possible duplicate of [How to plug my Autofac container into ASP. NET Identity 2.1](http://stackoverflow.com/questions/24391885/how-to-plug-my-autofac-container-into-asp-net-identity-2-1) – Cyril Durand Apr 24 '16 at 15:11
  • Were you just looking for the syntax of how to install an Autofac component? – tacos_tacos_tacos Apr 24 '16 at 15:32
  • @Jen nvm, I see you had the AutoFac syntax in your question. Well, what is it that you wan to know? The repository pattern you speak of is part of the design of that set of types by M$` – tacos_tacos_tacos Apr 24 '16 at 15:33

1 Answers1

2

Some examples I found on the Internet.

1. Registering roles, users, associations

https://github.com/kirill-vinnichek/BerezovskyVinnichek.Wunderlist/blob/master/Wunderlist/Epam.Wunderlist.Web/App_Start/AutofacConfig.cs

public static class AutofacConfig
{
    public static void Config()
    {
        var builder = new ContainerBuilder();
        builder.RegisterControllers(Assembly.GetExecutingAssembly());
        builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
        builder.RegisterFilterProvider();
        builder.RegisterModule(new AutofacDataModule());
        builder.RegisterModule(new AutofacServiceModule());

        builder.RegisterType<WunderlistUserStore>().As<IUserStore<OwinUser,int>>().InstancePerRequest();
        builder.RegisterType<WunderlistRoleStore>().As<IRoleStore<OwinRole,int>>().InstancePerRequest();
        builder.RegisterType<WunderlistUserManager>().As<UserManager<OwinUser,int>>().InstancePerRequest();

        IContainer container = builder.Build();

        System.Web.Mvc.DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
    }
}

2. Registering user store

https://github.com/cococrm/ZY.Web/blob/master/ZY.WebApi/Autofac/RepositoryModule.cs

    protected override void Load(ContainerBuilder builder)
    {
        builder.RegisterGeneric(typeof(Repository<,>)).As(typeof(IRepository<,>));
        builder.RegisterType<UserStore>().As<IUserStore<User,int>>();
    }
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126