Demo/Demo.WebApi/Core/InfrastructureExtensions.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using Microsoft.Extensions.DependencyInjection;
using Kernelx.Contexts;
using Kernelx.Cmpts.MOI;
using Kernelx.Cmpts.EFMOI;
using Microsoft.EntityFrameworkCore;
using System;
using Kernelx.Contexts.Core.SequeGenerator;
using Microsoft.Extensions.Configuration;
using System.Text.Json;
using Kernelx.Cmpts.ServiceModels.Default;
using System.ComponentModel.DataAnnotations;
using Demo.WebApi.Core;
using Kernelx.Cmpts.ServiceModels;
namespace Demo.WebApi
{
internal class Constants
{
public const string MsSql = "MsSql";
}
public class DefaultInputValidator2 : DefaultInputValidator
{
public override ValidationResult Validation(ValidationAttribute attribute, object value, ValidationContext validationContext)
{
var result = base.Validation(attribute, value, validationContext);
if (result != null && !string.IsNullOrEmpty(result.ErrorMessage))
{
if (attribute is RequiredAttribute)
return new ValidationResult($"参数[{validationContext.DisplayName}]的值为必填项,不能为空");
else if (attribute is MaxLengthAttribute max)
return new ValidationResult($"参数[{validationContext.DisplayName}]的值的长度不能大于{max.Length}个字符");
}
return result;
}
}
public static class InfrastructureExtensions
{
internal static IServiceCollection AddEFModelibContext<TService, TImplementation>(this IServiceCollection services,
string dbType, string connectionString, bool isDefault = false)
where TService : class, IModelibContext
where TImplementation : EFModelibContextBase, TService
{
services.AddDbContext<TImplementation>(options =>
{
if (dbType == Constants.MsSql)
options.UseSqlServer(connectionString);
}, ServiceLifetime.Scoped);
services.AddScoped<TService, TImplementation>();
if (isDefault)
services.AddScoped<IUnitOfWork, TImplementation>();
return services;
后面还有 37 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
