Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Service that will use users
- public class QuizesService : IQuizesService
- {
- private readonly IDbRepository<Quiz> quizzes;
- private readonly UserManager<ApplicationUser> manager;
- private readonly IIdentifierProvider identifierProvider;
- public QuizesService(
- IDbRepository<Quiz> quizzes,
- IIdentifierProvider identifierProviders,
- UserManager<ApplicationUser> manager)
- {
- this.quizzes = quizzes;
- this.identifierProvider = identifierProviders;
- this.manager = manager;
- // Now you can access users
- var user = this.manager.Users.FirstOrDefault(u => u.Email == "nesthosi");
- this.manager.Delete(user);
- }
- }
- // In Autofac
- private static void RegisterServices(ContainerBuilder builder)
- {
- builder.Register(x => new ApplicationDbContext())
- .As<DbContext>()
- .InstancePerRequest();
- builder.Register(x => new HttpCacheService())
- .As<ICacheService>()
- .InstancePerRequest();
- builder.Register(x => new IdentifierProvider())
- .As<IIdentifierProvider>()
- .InstancePerRequest();
- // Add This
- builder.RegisterType<UserStore<ApplicationUser>>()
- .As<IUserStore<ApplicationUser>>();
- builder.RegisterType<UserManager<ApplicationUser>>();
- // Up to here
- var servicesAssembly = Assembly.GetAssembly(typeof(IQuizesService));
- builder.RegisterAssemblyTypes(servicesAssembly)
- .AsImplementedInterfaces();
- builder.RegisterGeneric(typeof(DbRepository<>))
- .As(typeof(IDbRepository<>))
- .InstancePerRequest();
- builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
- .AssignableTo<BaseController>().PropertiesAutowired();
- }
Add Comment
Please, Sign In to add comment