小编br3*_*3nt的帖子

如何将 healthcheck 端点添加到 ApiExplorer 以便 Swashbuck 将其包含在生成的 swagger.json 中

我已将Microsoft.AspNetCore.Diagnostics.HealthChecks样式健康检查添加到我的应用程序中,如Microsoft 此处所述

我还使用Swashbuckle生成一个 swagger 文档。然后,我使用NSwag生成客户端 API 供其他应用程序使用。

问题是Startup.csMapHealthChecks中添加的运行状况检查端点没有添加到. 这是一个问题,因为 Swashbuckle 使用它来生成 swagger 文档。ApiExplorer

所以我的问题是将健康检查端点添加到 ApiExplorer 以便 Swashbuckle 可以将其包含在 swagger 文件中的最佳方法是什么?

我尝试手动添加健康检查端点add ApiExplorer(代码如下)。应用程序成功运行,但 swagger 文档不包含端点。

// from Startup.cs

public virtual void ConfigureServices(IServiceCollection services)
{
    // ...

    // add swagger
    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
    });

    // add healthchecks
    services
        .AddHealthChecks()
        .AddDbContextCheck<DatabaseDomain.DbContext>(tags: new[] { "db" })
        ;

    // ...

} …
Run Code Online (Sandbox Code Playgroud)

swagger asp.net-mvc-apiexplorer swashbuckle asp.net-core

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

当 v-model 值更改时,自定义 Vue 选择组件不会更新所选选项

我正在尝试使用文档中v-model描述的模式将选择包装在 Vue 自定义组件中。

我面临的问题是我的自定义选择组件收到以下错误消息:

[Vue warn]:避免直接改变 prop,因为每当父组件重新渲染时,该值都会被覆盖。相反,根据 prop 的值使用数据或计算属性。道具被变异:“value”

在发现

--->

但是,当我创建value数据属性时,我失去了预期的功能。也就是说,当绑定值更改时,选择框不会更新。双向绑定丢失。

在不发出警告的情况下维持我期望的行为的正确方法是什么?

这是演示该问题的交互式示例(最好在全屏下查看)。

Vue.component('dynamic-select-ex1', {
  template: '#dynamic-select-template',
  props: ['value', 'options'],
  methods: {
    changed() {
      // custom input components need to emit the input event
      this.$emit('input', event.target.value)
    },
  },
})

Vue.component('dynamic-select-ex2', {
  template: '#dynamic-select-template',
  props: ['options'],
  data() {
    return {
      value: null,
    }
  },
  methods: {
    changed() {
      // custom input components need to emit the input event
      this.$emit('input', event.target.value)
    },
  },
})

let example = …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vue-component vuejs2 vue-props

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

搭建完整的 .Net Identity UI 源后,身份/帐户/管理页面的布局被破坏

我正在遵循这些指南:

  1. 未经现有授权将 Scaffold Identity 添加到 MVC 项目中
  2. 创建完整的 Identity UI 源

遵循第一个指南后,我得到了我对“身份/帐户/管理”页面的期望: 在此输入图像描述

然而,在遵循第二个指南后,布局被破坏了。侧面菜单丢失。该应用程序不再找到Areas/Identity/Pages/Account/Manage/_Layout.cshtml,我不明白为什么。

在此输入图像描述

这是 git diff。

namespace WebIdentity.Areas.Identity
{
    public class IdentityHostingStartup : IHostingStartup
    {
        public void Configure(IWebHostBuilder builder)
        {
            builder.ConfigureServices((context, services) => {
                services.AddDbContext<IdentityDbContext>(options =>
                    options.UseSqlServer(
                        context.Configuration.GetConnectionString("IdentityDbContextConnection")));
 
-                services.AddDefaultIdentity<User>(options => options.SignIn.RequireConfirmedAccount = true)
-                    .AddEntityFrameworkStores<IdentityDbContext>();
+                services
+                    .AddIdentity<User, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
+                    .AddEntityFrameworkStores<IdentityDbContext>()
+                    .AddDefaultTokenProviders();
+
+                services
+                    .AddMvc()
+                    .AddRazorPagesOptions(options =>
+                    {
+                        options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
+                        options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
+                    });
+ …
Run Code Online (Sandbox Code Playgroud)

asp.net-identity asp.net-core-mvc asp.net-core asp.net-core-5.0

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

有没有办法为静态类方法定义别名?

基本上我的问题如标题中所述......

我想让用户能够为类中的静态方法定义别名(在我的情况下专门针对MyClass).

我没有找到类似于class_alias的任何功能.当然,用户可以定义自己的函数来调用静态方法来实现这个目标......但还有其他/更好/更简单/不同的方法吗?

这是我到目前为止的尝试......

<?php
class MyClass {

    /**
     * Just another static method.
     */
    public static function myStatic($name) {
        echo "Im doing static things with $name :)";
    }

    /**
     * Creates an alias for static methods in this class.
     *
     * @param   $alias      The alias for the static method
     * @param   $method     The method being aliased
     */
    public static function alias($alias, $method) {
        $funcName = 'MyClass::'.$method;    // TODO: dont define class name with string :p
        if (is_callable($funcName)) {
            $GLOBALS[$alias] …
Run Code Online (Sandbox Code Playgroud)

php alias static-methods

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

如何遍历存储在变量中的目录路径

我正在教我的自我bash并尝试创建一个脚本,它将遍历给定目录(或当前目录,如果没有提供)中包含的目录.

这是我到目前为止的脚本:

#!/bin/bash
start_dir=${1:-`pwd`}       # set to current directory or user supplied directory
echo start_dir=$start_dir

for d in $start_dir ; do
    echo dir=$d
done
Run Code Online (Sandbox Code Playgroud)

首先,所有这个脚本当前都设置dstart_dirabd回显值start_dir.我想这是有道理的,但我希望它实际上会遍历目录.如何让它实际循环遍历start_dir变量中设置的目录?

另外,我只想循环遍历目录. 这个答案表明,放在/路径之后将确保只有目录返回到for循环.有没有办法合并这个以确保循环start_dir只会返回目录,因为用户可能不会提供脚本的目录路径?

干杯

bash

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

将值从字典转换为NSNumber

我有一个NSDictionary对象,它保存从某些JSON对象转换的数据.

我的问题是一些数字存储为字符串,其他数字存储为整数.即在NSDictionary中,数字可以是NSString类型或NSNumber类型.不知何故,我必须转换数字,以便它们总是返回NSNumber.

这是我到目前为止提出的解决方案:

#import "Convert.h"
@implementation Convert
+(NSNumber *)toInteger:(NSObject *)object {
    if ([object isKindOfClass:[NSNumber class]]) {
        return (NSNumber *) object;
    }
    else if ([object isKindOfClass:[NSString class]]) {

        // Create number formatter
        NSNumberFormatter *formatInt = [[NSNumberFormatter alloc] init];
        [formatInt setNumberStyle:NSNumberFormatterDecimalStyle];

        // return formatted number
        return [formatInt numberFromString:(NSString *) object];
    }
    else {
        return 0;
    }
}
@end
Run Code Online (Sandbox Code Playgroud)

在行动:

NSNumber *myint;
myint = [Convert toInteger:[dict valueForKeyPath:@"myobj.numberAsString"]];
myint = [Convert toInteger:[dict valueForKeyPath:@"myobj.numberAsInteger"]];
Run Code Online (Sandbox Code Playgroud)

这很有效,但看起来很长很啰嗦而且不是很便宜.还有另外一种我没有考虑过的方法吗?

objective-c type-conversion ios

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

无法按命名函数的结果进行分组

NoMethodError: undefined method relation' for <Arel::Nodes::NamedFunction:0x7633>当我尝试按命名函数的结果进行分组时,我得到了。

class Appointment < ActiveRecord::Base
  scope :group_by_date, -> { group(date_column) }

  def self.date_column
    Arel::Nodes::NamedFunction.new(:date, [Appointment.arel_table[:start_time]], 'date')
  end
end

Appointment.group_by_date.count
# results in NoMethodError: undefined method `relation' for #<Arel::Nodes::NamedFunction:0x7633>
Run Code Online (Sandbox Code Playgroud)

这看起来完全合理,所以我不确定为什么会产生错误。我很确定这在早期版本的 Rails 中是可能的,如这个 SO 答案所示。

我期望得到类似于以下 sql 的内容:

SELECT date(appointments.start_time) AS date, COUNT(appointments.*) AS count
FROM appointments
GROUP BY date(appointments.start_time)
Run Code Online (Sandbox Code Playgroud)

有办法让它发挥作用吗?有没有办法将其转换Arel::Nodes::NamedFunctionArel::Attributes::Attribute

这显然是一个幼稚的解决方案尝试(它不起作用):

function = Arel::Nodes::NamedFunction.new('date', [Appointment[:start_time]])
attr = Arel::Attributes::Attribute.new(function)
Appointment.group(attr).to_sql
# NoMethodError: undefined method `table_alias' for #<Arel::Nodes::NamedFunction:0x4b8>
Run Code Online (Sandbox Code Playgroud)

我真的不想回到 using ,Appointment.group( …

ruby-on-rails arel ruby-on-rails-4

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