小编Poi*_*shi的帖子

如何将 httpClient 注入到实例化服务中?

我在 app.module.ts 中实例化 MyService,并在我的代码中提供它。

但是,我希望 MyService 使用 httpClient,并且我无法以角度惯用方式实例化 httpClient 以作为参数传递给 MyService。我不确定在 MyService 中访问 httpClient 的正确方法是什么。

我考虑过直接实例化 httpClient ,然后将其作为参数传递给我的服务。然而,这似乎造成了循环依赖。我也尝试过弄乱注入器,但显然 Angular 团队特别建议不要这样做。我强烈地觉得我错过了一些简单的东西。

应用程序模块.ts

imports: [
    ...
    httpClientModule
    ...
],

function MainServiceFactory() {
    return new MyService();
}
...
providers: [{
    provide: MyService,
    useFactory: MainServiceFactory
}],
...
Run Code Online (Sandbox Code Playgroud)

MyService.ts

...
constructor(private http : HttpClient) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

如果没有实例化并作为 httpClient 的参数传递:我自然会收到“app.module.ts 中的错误,预期 1 个参数”!通过实例化,我打破了角度建议。

编辑: 我忽略了指定我确实导入了 httpClientModule

angular angular-httpclient

5
推荐指数
1
解决办法
8569
查看次数

获得新的 access_token 后,如何更新我的 cookie?

使用刷新令牌获取新的访问令牌后,我想用该访问令牌更新我的客户端 cookie。

我的客户能够使用 ajax 登录并调用我的 REST API,但是当第一次授权到期时,API 调用自然不再起作用。

我有一个 .NET Web 应用程序,它使用自己的 REST API。API 是同一个项目的一部分。它没有自己的启动配置。

由于 cookie 是在每个请求的标头中发送的,因此它需要具有新的未过期访问令牌,以便我不会收到“用户未经授权”的请求。

现在我可以使用我的刷新令牌获得一个新令牌,但 cookie 的值没有改变,所以我相信在客户端发送任何请求之前我需要更新我的 cookie 以反映新的访问令牌。

这是我的混合客户端:

using IdentityModel.Client;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using Owin;
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Net;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;

namespace Cts.HomeService.Web.App_Start
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            var identityServerSection = (IdentityServerSectionHandler)System.Configuration.ConfigurationManager.GetSection("identityserversection");

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies",
                CookieManager = new Microsoft.Owin.Host.SystemWeb.SystemWebChunkingCookieManager()
            });


            app.UseOpenIdConnectAuthentication(new …
Run Code Online (Sandbox Code Playgroud)

.net c# owin identityserver4

5
推荐指数
1
解决办法
785
查看次数

postgres和Unicorn服务器的问题

当我尝试建立的Postgres运行后独角兽(与特里尼达和薄完美的作品),我收到以下错误.

dyld: lazy symbol binding failed: 
Symbol not found: _rb_thread_select 
Referenced from:/Users/pls/.rvm/gems/ruby-2.2.0@coinino/extensions/x86_64-darwin-13/2.2.0/do_postgres-0.10.14/do_postgres/do_postgres.bundle
  Expected in: flat namespace
Run Code Online (Sandbox Code Playgroud)

Datamapper通常在model.rb中连接到数据库,然后在app.rb中需要它.

有什么问题,我该如何解决?

编辑:看起来这是Ruby 2.2.0中的一个错误.

postgresql unicorn server

1
推荐指数
1
解决办法
834
查看次数