本文整理汇总了C#中IServiceCollection.AddAutoMapper方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceCollection.AddAutoMapper方法的具体用法?C# IServiceCollection.AddAutoMapper怎么用?C# IServiceCollection.AddAutoMapper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceCollection
的用法示例。
在下文中一共展示了IServiceCollection.AddAutoMapper方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AppSettings>(opt => Configuration.GetSection("AppSettings"));
services.AddMvc()
.AddVersionEndpoint();
services.AddBusinessServices();
services.AddAutoMapper();
services.AddSwaggerGen();
}
示例2: ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
// Check out ExampleController to find out how these configs are injected into other classes
services.Configure<AppSettings>(Configuration.GetSection("AppSettings"));
//--dataaccess-startupServices--
services.AddMvc()
.AddVersionEndpoint();
services.AddBusinessServices();
services.AddAutoMapper();
services.AddSwaggerGen();
services.AddGlobalErrorHandling<ApiExceptionMapper>();
}
示例3: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var path = PlatformServices.Default.Application.ApplicationBasePath;
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<UkuContext>(options =>
options.UseSqlite("Filename=" + Path.Combine(path, "uku.db")));
// Add framework services.
services.AddMvc();
// Need to do this if the UkuContext does not inlcude a constructor which takes options. That's only a problem for the interface though, not the concrete type. No idea why.
//services.AddTransient<IUkuContext, UkuContext>(p => p.GetRequiredService<UkuContext>());
services
.AddScoped<IUkuContext, UkuContext>()
.AddScoped<IAlbumService, AlbumService>();
services.AddAutoMapper();
}
示例4: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), o => o.EnableRetryOnFailure()));
services.Configure<DRSConfig>(Configuration.GetSection("DRS"));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
//services.AddReact();
services
.AddMvc(
options =>
{
options.Conventions.Add(new FeatureConvention());
options.Filters.Add(new ValidateModelStateFilter());
options.Filters.Add(new ApiExceptionFilter());
})
.AddRazorOptions(options =>
{
// {0} - Action Name
// {1} - Controller Name
// {2} - Area Name
// {3} - Feature Name
//options.AreaViewLocationFormats.Clear();
options.AreaViewLocationFormats.Add("/Areas/{2}/Features/{3}/{1}/{0}.cshtml");
options.AreaViewLocationFormats.Add("/Areas/{2}/Features/{3}/{0}.cshtml");
options.AreaViewLocationFormats.Add("/Areas/{2}/Features/Shared/{0}.cshtml");
options.AreaViewLocationFormats.Add("/Areas/Shared/{0}.cshtml");
// replace normal view location entirely
//options.ViewLocationFormats.Clear();
options.ViewLocationFormats.Add("/Features/{3}/{1}/{0}.cshtml");
options.ViewLocationFormats.Add("/Features/{3}/{0}.cshtml");
options.ViewLocationFormats.Add("/Features/Shared/{0}.cshtml");
options.ViewLocationExpanders.Add(new FeatureViewLocationExpander());
})
.AddJsonOptions(
options =>
{
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
})
.AddFluentValidation(cfg => { cfg.RegisterValidatorsFromAssemblyContaining<Startup>(); });
services.AddAutoMapper(typeof(Startup));
Mapper.AssertConfigurationIsValid();
services.AddMediatR(typeof(Startup));
var container = new Container(cfg => { cfg.AddRegistry<WebRegistry>(); });
// populates structuremap with .NET services
container.Populate(services);
return container.GetInstance<IServiceProvider>();
}
示例5: ConfigureServices
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc(options =>
{
options.Filters.Add(typeof(JsonExceptionFilter));
});
services.AddDbContext<AppDbContext>(opt => opt.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);
services.AddAutoMapper();
services.AddOptions();
services.Configure<TokenProviderOptions>(Configuration.GetSection("tokenOptions"));
}