我有一个像这样的简单 JS“枚举”
const MyEnum = {
Aaa: 1,
Bbb: 84,
};
Run Code Online (Sandbox Code Playgroud)
我有一个简单的故事:
import MyEnum from 'models/my-enum';
import HotSpot from 'hot-spot/hot-spot.vue';
import hotSpotProp from './hot-spot.stories.defaults';
export default {
title: 'components/catalog/images/HotSpot',
args: {
hotspotProp: hotSpotProp,
currentWidth: 360,
selectedCallouts: [],
calloutMode: true,
originalWidth: 2100,
title: 'Example tooltip',
},
argTypes: {
oemId: {
options: Object.keys(MyEnum), // an array of serializable values
mapping: MyEnum, // maps serializable option values to complex arg values
control: {
type: 'select', // type 'select' is automatically inferred when 'options' …Run Code Online (Sandbox Code Playgroud) 我正在使用 OpenApi 3.0 和 Swagger UI。
(如果重要的话,Swashbuckle 和 ASP.Net Core)
我有multipart/form-data两个参数:
ProductToAddJSON 中的对象描述Image作为文件。我已经定义了模式和示例。
我的目标是这样的:
我的问题是如何呈现第二张图片中的模式和示例?我在 swagger.json 等中没有找到任何有用的东西。
诗。如果你有好奇心,就可以完美地执行工作。
@编辑
我为此制作了 nuget 包。你可以在这里找到它
我需要检查数据库中特定对象中特定字段的权限。
让我们举个例子。我有模特叫Employee
public class Employee {
[Key]
public int EmployeeID { get; set; }
public string JobTitle { get; set; }
public string Description { get; set; }
public int Salary { get; set; } // <---- Restricted
public int BossID { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有几个案例:
我需要限制对特定领域的访问,Salary因为我不希望任何人看到彼此的薪水。但是 HR 可以看到任何人Salary并对其进行编辑。如果我是这个员工,我可以看到我自己的Salary,但不能编辑它。
每个人都可以看到彼此的职位名称,但只有 HR 可以编辑它。还有那个员工的老板,可以编辑,员工自己不能。
用例:
我是 RoleID 为 4 的经理。我想看看Salary我的Employee名字为 John Smith 的角色 ID为EmployeeID5。我可以做到。
我是 RoleID 4 的经理。我想看看 …
我正在使用自定义 WebApplication 工厂
public class CustomWebApplicationFactory<TStartup> : WebApplicationFactory<TStartup> where TStartup: class {
protected override void ConfigureWebHost(IWebHostBuilder builder) {
builder.ConfigureServices(services => {
// Create a new service provider.
var serviceProvider = new ServiceCollection()
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
services.AddDbContext<GrabGoContext>(options => {
options.UseInMemoryDatabase("GrabGoDb");
options.UseInternalServiceProvider(serviceProvider);
});
services.AddSingleton<TestEmailServer>();
services.AddScoped<IEmailProvider, TestEmailProvider>(); // <- HERE
});
base.ConfigureWebHost(builder);
}
Run Code Online (Sandbox Code Playgroud)
我想将我IEmailProvider调用的默认服务切换DefaultEmailProvider为我的特殊服务TestEmailProvider,但问题是该方法ConfigureWebHost是在之前执行的Startup.ConfigureServices(IServiceCollection services),所以我的服务DefaultEmailProvider是在之后设置的TestEmailProvider。因此在我的ClientController服务中DeafultEmailProvider使用的是而不是测试服务。
我的问题是:
如何使用 WebApplicationFactory 切换DefaultEmailProvider服务TestEmailProvider?
@更新
好吧,我已经设法更深入了。我发现该方法builder.ConfigureTestServices() …
我试图写一些try catch对Convert.FromBase64String(),我发现它已经具有TryFromBase64String()方法。但是它需要3个参数:
public static bool TryFromBase64String(string s, Span<byte> bytes, out int bytesWritten);
Run Code Online (Sandbox Code Playgroud)
那我该怎么用 Span<byte> bytes呢?
我仅在文档中找到此内容,但没有适当的描述。也许这太明显了。
https://docs.microsoft.com/zh-cn/dotnet/api/system.convert.tryfrombase64string?view=netcore-2.1
感谢@Damien_The_Unbeliever和这篇文章,我发现了更多有关的信息Span。所以...
Span用于节省内存,因此不要调用太多。它可以存储数组或数组的一部分,但是我仍然不知道如何在该方法中使用它。
我正在使用 Google Cloud 托管我的 .Net Core 2.2 应用程序,但我想将其更新到 3.0。我的app.yaml看起来像这样
service: api
runtime: aspnetcore
env: flex
Run Code Online (Sandbox Code Playgroud)
我知道我可以在runtime部分中指定 .Net Core 版本。但是 Google Cloud Container Registry 没有 .Net Core 3.0。我在这里检查过。
那么我应该制作一个自定义容器吗?我对docker. 也许不知何故有一个随时可用的容器。
我没有在公共 Container Registry 中找到任何更新 .Net Core 镜像的路线图。
@更新
它正在工作!
我的dockerfile看起来像这样:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY MyProject.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . …Run Code Online (Sandbox Code Playgroud) 在MyDbContext中,我有LogChanges方法,该方法使用以下信息记录我的日志表中的所有更改:
TableName = entityName,
IDRow = JsonConvert.SerializeObject(primaryKeys),
Value = JsonConvert.SerializeObject(values),
Date = dateTimeNow,
Author = userFromJWT
Run Code Online (Sandbox Code Playgroud)
我想将Author设置为JWT授权的User。从这部分完全是:
“ sub”:“ myUserName”
如何在MyDbContext中获取该用户名?也许某种去掺杂剂注射?
提前致谢!
@解
启动文件
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options => {
options.TokenValidationParameters = new TokenValidationParameters {
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
};
});
services.AddHttpContextAccessor();
//...
}
Run Code Online (Sandbox Code Playgroud)
MyDbContext.cs
// ... …Run Code Online (Sandbox Code Playgroud) 我有类,它使用Console类并在构造函数中设置此变量.
public Scene() {
Height = Console.WindowHeight;
Width = Console.WindowWidth;
}
Run Code Online (Sandbox Code Playgroud)
和测试类,它测试这个构造函数:
public class SceneTests {
[Fact]
public void Contructor_None_ShouldReturnScene() {
var testScene = new Scene();
Assert.Equal(Console.WindowHeight, testScene.Height);
Assert.Equal(Console.WindowWidth, testScene.Width);
}
}
Run Code Online (Sandbox Code Playgroud)
但是在运行这个测试的时候,我有了Exeption:
Exception has occurred: CLR/System.IO.IOException
An exception of type 'System.IO.IOException' occurred in System.Console.dll but was not handled in user code: 'Nieprawid?owe doj?cie'
at System.ConsolePal.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at System.ConsolePal.get_WindowHeight()
at System.Console.get_WindowHeight()
Run Code Online (Sandbox Code Playgroud)
我想,那是因为我没有实际的Console窗口.
我可以以某种方式模拟那个吗?也许简单地手动创建缓冲区并添加它将Console解决问题.
c# ×6
asp.net-core ×5
.net-core ×3
base64 ×1
javascript ×1
jwt ×1
storybook ×1
swagger ×1
swagger-ui ×1
swashbuckle ×1
terminal ×1
vue.js ×1
xunit ×1