I specify mapster service operations in web program.cs in layered architecture, but I want to use this application in another layer. And I'm having trouble choosing assembly.
Web Layer Program.cs
var config = TypeAdapterConfig.GlobalSettings;
config.Scan(Assembly.GetAssembly(typeof(UserMappingConfig)));
builder.Services.AddSingleton(config);
builder.Services.AddScoped<IMapper, ServiceMapper>();
Service Layer Mapping Classes
namespace Exams.Service.Mapping
{
public class QuestionMappingConfig : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<QuestionViewModel, Question>().IgnoreNullValues(true);
config.NewConfig<List<QuestionViewModel>,List<Question>>().IgnoreNullValues(true);
config.NewConfig<Question, QuestionViewModel>().IgnoreNullValues(true);
}
}
}
I am getting a warning like this
Severity Code Description Project File Line Suppression State Warning CS8604 Possible null reference argument for parameter 'assemblies' in 'IList TypeAdapterConfig.Scan(params Assembly[] assemblies)'.
To summarize, for the Mapster application that I have to define in the Web layer, I want to use the configurations that I defined in the Service layer in the Service layer, but I have trouble choosing the assembly. How can I fix?
Assembly.GetAssembly
returns Assembly?
(see nullable reference types ), you can either use null-forgiving operator ( !
):
config.Scan(Assembly.GetAssembly(typeof(UserMappingConfig))!);
Or just use Assembly
from the type instance:
config.Scan(typeof(UserMappingConfig).Assembly);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.