public static IEasyNetBuilder AddIdentityCore <TDbContext, TUser>( this IEasyNetBuilder builder, Action <IdentityOptions> identitySetupAction = null, Action <AuthenticationOptions> authenticationSetupAction = null) where TDbContext : EasyNetDbContext where TUser : class { Check.NotNull(builder, nameof(builder)); builder.Services .AddAuthentication(o => { o.DefaultScheme = IdentityConstants.ApplicationScheme; o.DefaultSignInScheme = IdentityConstants.ExternalScheme; authenticationSetupAction?.Invoke(o); }); builder.Services .AddIdentityCore <TUser>(o => { o.Stores.MaxLengthForKeys = 128; identitySetupAction?.Invoke(o); }) .AddUserManager <EasyNetUserManager <TUser> >() .AddSignInManager <EasyNetSignInManager <TUser> >() .AddEntityFrameworkStores <TDbContext>(); builder.Services.TryAddScoped <IEasyNetGeneralSignInManager, EasyNetSignInManager <TUser> >(); return(builder); }
/// <summary> /// Executes database migration command when EasyNet initialization. /// </summary> /// <typeparam name="TDbContext">The context associated with the application.</typeparam> /// <param name="builder">The <see cref="IEasyNetBuilder"/>.</param> /// <returns></returns> public static IEasyNetBuilder AddDatabaseMigrationJob <TDbContext>(this IEasyNetBuilder builder) where TDbContext : EasyNetDbContext { Check.NotNull(builder, nameof(builder)); builder.AddInitializationJob(typeof(DatabaseMigrationJob <TDbContext>)); return(builder); }
/// <summary> /// Add a new <see cref="IEasyNetSession"/> implementation. /// </summary> /// <typeparam name="TSession"></typeparam> /// <param name="builder">The <see cref="IEasyNetBuilder"/>.</param> /// <returns>An <see cref="IEasyNetBuilder"/> that can be used to further configure the EasyNet services.</returns> public static IEasyNetBuilder AddSession <TSession>(this IEasyNetBuilder builder) where TSession : IEasyNetSession { Check.NotNull(builder, nameof(builder)); builder.Services.Replace(new ServiceDescriptor(typeof(IEasyNetSession), typeof(TSession), ServiceLifetime.Scoped)); return(builder); }
/// <summary> /// Configure <see cref="UnitOfWorkDefaultOptions"/> /// </summary> /// <param name="builder">The <see cref="IEasyNetBuilder"/>.</param> /// <param name="setupAction">An <see cref="Action{UnitOfWorkDefaultOptions}"/> to configure the provided <see cref="UnitOfWorkDefaultOptions"/>.</param> /// <returns>An <see cref="IEasyNetBuilder"/> that can be used to further configure the EasyNet services.</returns> public static IEasyNetBuilder ConfigureUnitOfWorkDefaultOptions(this IEasyNetBuilder builder, Action <UnitOfWorkDefaultOptions> setupAction) { Check.NotNull(builder, nameof(builder)); Check.NotNull(setupAction, nameof(setupAction)); builder.Services.Configure(setupAction); return(builder); }
/// <summary> /// Add specified services to let the system support EntityFrameworkCore. /// </summary> /// <typeparam name="TDbContext">The context associated with the application.</typeparam> /// <param name="builder">The <see cref="IEasyNetBuilder"/>.</param> /// <param name="setupAction">An <see cref="Action{DbContextOptionsBuilder}"/> to configure the provided <see cref="DbContextOptionsBuilder"/>.</param> /// <param name="asMainOrmTechnology"> /// Sometimes use more than one orm technology in one system. We need to choice one of them as main technology. /// Use this value to control which orm is main technology. /// We can use <see cref="IRepository{TEntity,TPrimaryKey}"/> to get a repository service if this value is true. We also can use <see cref="IEfCoreRepository{TEntity,TPrimaryKey}"/> at the same time. /// </param> /// <returns></returns> public static IEasyNetBuilder AddEfCore <TDbContext>(this IEasyNetBuilder builder, Action <DbContextOptionsBuilder> setupAction, bool asMainOrmTechnology) where TDbContext : EasyNetDbContext { Check.NotNull(builder, nameof(builder)); Check.NotNull(setupAction, nameof(setupAction)); builder.Services .AddDbContext <TDbContext>(setupAction) .Replace(new ServiceDescriptor(typeof(IUnitOfWork), typeof(EfCoreUnitOfWork), ServiceLifetime.Transient)) .AddScoped <IDbContextProvider <TDbContext>, UnitOfWorkDbContextProvider <TDbContext> >(); RegisterRepositories <TDbContext>(builder.Services, asMainOrmTechnology); return(builder); }
/// <summary> /// Add a job to be executed when EasyNet initialization. /// </summary> /// <param name="builder">The <see cref="IEasyNetBuilder"/>.</param> /// <param name="jobTypes">The job which need to be executed when EasyNet initialization.</param> /// <returns>An <see cref="IEasyNetBuilder"/> that can be used to further configure the EasyNet services.</returns> public static IEasyNetBuilder AddInitializationJob(this IEasyNetBuilder builder, params Type[] jobTypes) { Check.NotNull(builder, nameof(builder)); Check.NotNullOrEmpty(jobTypes, nameof(jobTypes)); foreach (var type in jobTypes) { if (!typeof(IEasyNetInitializationJob).IsAssignableFrom(type)) { throw new EasyNetException($"Type {type.AssemblyQualifiedName} does not inherit {typeof(IEasyNetInitializationJob).AssemblyQualifiedName}."); } builder.Services.TryAddTransient(type); builder.Services.Configure <EasyNetInitializerOptions>(options => { options.JobTypes.Add(type); }); } return(builder); }
public static IEasyNetBuilder AddIdentity <TUser>( this IEasyNetBuilder builder, Action <IdentityBuilder> identitySetupAction, Action <AuthenticationOptions> authenticationSetupAction = null) where TUser : class { Check.NotNull(builder, nameof(builder)); Check.NotNull(identitySetupAction, nameof(identitySetupAction)); builder.Services .AddAuthentication(o => { o.DefaultScheme = IdentityConstants.ApplicationScheme; o.DefaultSignInScheme = IdentityConstants.ExternalScheme; authenticationSetupAction?.Invoke(o); }); builder.Services.TryAddScoped <IEasyNetGeneralSignInManager, EasyNetSignInManager <TUser> >(); identitySetupAction(new IdentityBuilder(typeof(TUser), builder.Services)); return(builder); }