小编Ner*_*ero的帖子

Asp.net core 2.0 AutoMapper IValueResolver 依赖注入

我已经尝试了 Google Results、Stackoverflow 和 AutoMapper 中的大部分示例。但无法使 IValueResolverdependancy 注入工作。

我有以下服务

public class StorageService : IStorageService
{
    private readonly BlobServiceSettings _blobServiceSettings;

    public StorageService(IOptions<BlobServiceSettings> blobServiceSettings)
    {
        _blobServiceSettings = blobServiceSettings.Value;
    }

    // some methods I need
}
Run Code Online (Sandbox Code Playgroud)

这是我的个人资料

public class MappingProfile : Profile
{
    public MappingProfile()
    {
        CreateMap<Building, BuildingEnvelope>(MemberList.None)
        .ForMember(dest => dest.ImageUrl, opt => opt.ResolveUsing<BuildingImageUrlResolver>());
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 IValueResolver

public class BuildingImageUrlResolver : IValueResolver<Building,         BuildingEnvelope, string>
{
    private readonly IStorageService _storageService;
    public BuildingImageUrlResolver(IStorageService storageService)
    {
        _storageService = storageService;
    }

    public string Resolve(Building entity, BuildingEnvelope …
Run Code Online (Sandbox Code Playgroud)

dependency-injection resolver automapper asp.net-core-2.0

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

asp net core项目使用Cookie认证的MVC控制器和使用Bearer的api端点

我正在使用ASP .net CORE开发一个项目,我们有Angular 2和MVC以及API,需要受Azure AD保护.

Home/Index MVC控制器将启动Angular 2 SPA,Home/Index需要通过cookie身份验证进行保护.我设法使用OpenIdConnectAuthentication - OnAuthorizationCodeReceived事件获取令牌.

我需要使用基于Cookie的身份验证和使用承载身份验证的API来保护MVC控制器(除了Home/Index之外还有更少的控制器),我可以从API获取令牌到Angular,然后在每次后续API调用时使用该令牌.

在不久的将来,将会有使用Bearer令牌调用相同API端点的移动应用程序.

这是我的出发点:https: //docs.microsoft.com/en-us/azure/active-directory/active-directory-appmodel-v2-overview

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
   services.AddMvc().AddJsonOptions(config => { config.SerializerSettings.ContractResolver = new DefaultContractResolver(); });

   services.AddAuthentication(sharedOptions => sharedOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
   app.UseCookieAuthentication(new CookieAuthenticationOptions());

   Authority = $"https://login.microsoftonline.com/AAAAA}";
   ClientId = "BBBB";
   ClientSecret = "CCCC";
   Audience = "https://localhost:44333/";

   app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
   {
      ClientId = ClientId,
      Authority = Authority,
      PostLogoutRedirectUri = Audience,
      ResponseType = OpenIdConnectResponseType.CodeIdToken,
      GetClaimsFromUserInfoEndpoint = false,
      Events = …
Run Code Online (Sandbox Code Playgroud)

asp.net single-sign-on asp.net-web-api asp.net-core

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

如何提高具有 OPENJSON 来过滤 JSON 数组属性的 T-SQL 查询的性能

我有一个包含 JSON 数组列 ( nvarchar(max)) 的表,有数百万行,预计将来会有数十亿行。

表结构是这样的:

[SnapshotId] - PK,
[BuildingId],
......................
[MeterData],
Run Code Online (Sandbox Code Playgroud)

MeterData 包含这样的 Json 数组:

[{
    "MeterReadingId": 0,
    "BuildingMeterId": 1,
    "Value": 1.0,   
}, {
    "MeterReadingId": 0,
    "BuildingMeterId": 2,
    "Value": 1.625, 
}]
Run Code Online (Sandbox Code Playgroud)

我需要按“HourlySnapshot”表过滤,其中“BuildingMeterId = 255”是例如,写了下面的查询

SELECT * 
FROM [HourlySnapshot] h 
CROSS APPLY OPENJSON(h.MeterData) 
    WITH (BuildingMeterId int '$.BuildingMeterId') AS MeterDataJson
WHERE MeterDataJson.BuildingMeterId = 255
Run Code Online (Sandbox Code Playgroud)

工作正常,但由于解析 JSON,性能很差。我读到您可以通过创建索引来克服性能问题。我创建了一个如下所示的聚集索引

CREATE CLUSTERED INDEX CL_MeterDataModel 
    ON [HourlySnapshot] (MeterDataModel)
Run Code Online (Sandbox Code Playgroud)

但是在速度方面看不到任何改进。我做错了吗?什么是提高速度的最佳方法。

谢谢

尼禄无英雄

sql-server performance json

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

Angular 2 Observable Service从localStorage返回数据

我在扩展Observables服务后从本地存储返回数据.

场景:组件将订阅Service.GetAll()和GetAll()将在localStorage中查找数据,如果发现它将返回,否则它将进行api调用以获取数据.

我设法使用Promise,但我更喜欢将其转换为Observables

getAll(): Promise<IScheduleFrequency[]> {
    let ScheduleFrequencies: IScheduleFrequency[] = this.storageService.get('ScheduleFrequencies');
    if (ScheduleFrequencies != null) {
        return Promise.resolve(ScheduleFrequencies);
    } else {
        return this.http.get(this.apiUrl)
            .toPromise()
            .then((response) => {
                let ScheduleFrequencies: IScheduleFrequency[] = response.json();
                this.storageService.save('ScheduleFrequencies', activityScheduleFrequencies);
                return ScheduleFrequencies || [];
            })
            .catch(this.handleError);
    }
}
Run Code Online (Sandbox Code Playgroud)

适当的,如果有人可以告诉我如何延伸到服务以下做同样的事情.

getAll(): Observable<TransactionStatus[]> {
    return this.http.get(this.apiUrl)
        .map(this.extractData)
        .catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)

谢谢Asanka

更新 谢谢你@ nzjun90的回复工作需要导入'of'import'rxjs/add/observable/of';

service return observable angular

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