小编let*_*tie的帖子

FluentValidation:如何从另一个程序集自动注册所有验证器?

我正在为 .Net Core 项目使用“FluentValidation.AspNetCore”库(版本=“8.6.2”)。

我想做的是使用类似这样的东西(这就是我现在使用的)在 Startup.cs 类中自动注册所有验证器:

services.AddControllers().AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining<Startup>());
Run Code Online (Sandbox Code Playgroud)

但问题是我的验证器将被移动到另一个程序集(客户端需要),所以我不能使用 Startup 作为注册的参考。

有没有一种方法可以做到这一点,而不必一一注册验证器?

c# registration startup fluentvalidation .net-core

9
推荐指数
3
解决办法
3万
查看次数

Next.js 应用程序中在哪里设置 Sentry 的 setUser?

我一直在尝试将用户数据设置到 Sentry 的全局范围内,因此每次出现错误或事件时,用户信息都会传递给它。

我的应用程序是在 Next.js 中构建的,因此我很自然地添加了 Sentry 的 Next.js 文档中的配置。

我不知道在哪里添加 Sentry.setUser({id: user.Id}) 方法以使其全局设置用户。

到目前为止,我已将其添加到 Sentry 的 _error.js 文件中的 getInitialProps 方法中:

import NextErrorComponent from 'next/error';

import * as Sentry from '@sentry/nextjs';
import { getUser } from '../lib/session';

const MyError = ({ statusCode, hasGetInitialPropsRun, err }) => {
    if (!hasGetInitialPropsRun && err) {
        Sentry.captureException(err);
    }

    return <NextErrorComponent statusCode={statusCode} />;
};

MyError.getInitialProps = async (context) => {
    const errorInitialProps = await NextErrorComponent.getInitialProps(context);

    const { req, res, err, asPath } = context;

    errorInitialProps.hasGetInitialPropsRun …
Run Code Online (Sandbox Code Playgroud)

javascript sentry reactjs next.js

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