提交 76be9611 编写于 作者: K kuiyu

fix err

上级 29b9b385
......@@ -24,16 +24,21 @@ namespace RsCode.AspNetCore
{
public static class JwtExtensions
{
public static void AddJwt(this IServiceCollection services, string Url = "/UserAuthHub")
public static void AddJwt(this IServiceCollection services)
{
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
var jwt = JwtHelper.GetJwtInfo();
if (jwt.Expire < 0)
jwt.Expire = 60*24*360 ;
options.RequireHttpsMetadata = false;
options.SaveToken = true;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,//是否验证发行者
......@@ -48,19 +53,15 @@ namespace RsCode.AspNetCore
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwt.SecurityKey))
};
////signalr auth
//auth
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) &&
(path.StartsWithSegments(Url)))
{
if(context.Request.Query.TryGetValue("access_token", out var accessToken))
{
context.Token = accessToken;
}
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
......
......@@ -60,8 +60,8 @@ namespace RsCode
public static void AddDatabase<TDatabaseProvider>(this IServiceCollection services, string connString,IMapper defaultMapper=null)
where TDatabaseProvider : IProvider
{
services.AddScoped<IDatabase, Database>(x => new Database<TDatabaseProvider>(connString,defaultMapper));
services.TryAddScoped<IApplicationDbContext, ApplicationDbContext>();
services.AddTransient<IDatabase, Database>(x => new Database<TDatabaseProvider>(connString,defaultMapper));
services.TryAddTransient<IApplicationDbContext, ApplicationDbContext>();
}
/// <summary>
......@@ -71,8 +71,8 @@ namespace RsCode
/// <param name="func"></param>
public static void AddDatabase(this IServiceCollection services,Func<Database> func)
{
services.AddScoped<IDatabase, Database>(x => func());
services.TryAddScoped<IApplicationDbContext, ApplicationDbContext>();
services.AddTransient<IDatabase, Database>(x => func());
services.TryAddTransient<IApplicationDbContext, ApplicationDbContext>();
}
......
......@@ -47,23 +47,13 @@ namespace RsCode
public override async Task Invoke(AspectContext context, AspectDelegate next)
{
try
{
using (Uow)
{
Uow.Open(DbConnectionStringName);
await next(context);
Uow.Commit();
}
}
catch (Exception e)
{
throw e;
}
finally
{
}
}
......
......@@ -30,7 +30,8 @@ namespace RsCode
{
public static void AddUnitOfWork(this IServiceCollection services)
{
services.TryAddScoped<IApplicationDbContext, ApplicationDbContext>();
services.TryAddTransient<IApplicationDbContext, ApplicationDbContext>();
services.TryAddScoped(typeof(IRepository<>), typeof(Repository<>));
services.TryAddScoped<IUnitOfWork, PetaPocoUnitOfWork>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册