public static IAutoMapperBuilder AddAutoMapperInternal(this IServiceCollection services, Action <IServiceProvider, IMapperConfigurationExpression> configAction) { services = services ?? throw new ArgumentNullException(nameof(services)); if (configAction != null) { services.AddSingleton <IPostAutoMapperConfiguration>(new PostAutoMapperConfiguration(configAction)); } services.TryAddSingleton <IAutoMapperConfigurationProvider, AutoMapperConfigurationProvider>(); services.TryAddSingleton <IConfigurationProvider>(sp => { var postConfigs = sp.GetRequiredService <IEnumerable <IPostAutoMapperConfiguration> >(); //should be Singletion var mapConfigProvider = sp.GetRequiredService <IAutoMapperConfigurationProvider>(); //should be Singletion return(new MapperConfiguration(cfg => { foreach (var t in mapConfigProvider.GetMapProfileTypes()) { cfg.AddProfile(t); } //cfg.AddProfiles(); foreach (var config in postConfigs) { config?.Configuration(sp, cfg); } })); }); services.TryAddScoped <IMapper>(sp => new Mapper(sp.GetRequiredService <IConfigurationProvider>(), sp.GetService)); var builder = new AutoMapperBuilder(services); return(builder); }
private static void Main(string[] args) { Console.WriteLine("Initialize Automapper"); AutoMapperBuilder.RegisterAutoMapper(); Console.WriteLine("Seeding database"); var t = new PersonInfoDatabaseInitializer(); t.Seed(); Console.WriteLine("Running service"); var wcfProvider = new WcfServiceProvider(); wcfProvider.RunService(); }
// 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(); services.AddEntityFramework().AddDbContext <TrollChatDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Database"))); services.AddSession(); DependencyRegister.Register(services); QuartzDependencyRegister.Register(services); AutoMapperBuilder.Build(); services.Configure <EmailServiceCredentials>(Configuration.GetSection(nameof(EmailServiceCredentials))); services.AddSignalR(options => { options.Hubs.EnableDetailedErrors = true; options.Hubs.EnableJavaScriptProxies = true; }); services.AddAuthorization(options => { options.AddPolicy("UserPolicy", policyBuilder => { policyBuilder.RequireAuthenticatedUser() .RequireAssertion(context => context.User.HasClaim("Role", "User")) .Build(); }); }); // MiniProfiler services.AddMiniProfiler(options => { // (Optional) Path to use for profiler URLs, default is /mini-profiler-resources options.RouteBasePath = "/profiler"; // (Optional) Control which SQL formatter to use, InlineFormatter is the default options.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(); // (Optional) Control storage // (default is 30 minutes in MemoryCacheStorage) ((MemoryCacheStorage)options.Storage).CacheDuration = TimeSpan.FromMinutes(30); }).AddEntityFramework(); services.AddMemoryCache(); }
/// <summary> /// Use the KickStart extension to configure AutoMapper. /// </summary> /// <param name="configurationBuilder">The configuration builder.</param> /// <param name="configure">The <see langword="delegate"/> to configure AutoMapper options.</param> /// <returns> /// A fluent <see langword="interface"/> to configure KickStart. /// </returns> /// <example>Configure AutoMapper on application startup /// <code><![CDATA[ /// Kick.Start(config => config /// .IncludeAssemblyFor<UserProfile>() /// .UseAutoMapper(c => c /// .Validate() /// .Initialize(map => map.AddGlobalIgnore("SysVersion")) /// ) /// .LogLevel(TraceLevel.Verbose) /// );]]></code> /// </example> public static IConfigurationBuilder UseAutoMapper(this IConfigurationBuilder configurationBuilder, Action <IAutoMapperBuilder> configure) { var options = new AutoMapperOptions(); var service = new AutoMapperStarter(options); if (configure != null) { var builder = new AutoMapperBuilder(options); configure(builder); } configurationBuilder.ExcludeName("AutoMapper"); configurationBuilder.Use(service); return(configurationBuilder); }
static void Main() { AutoMapperBuilder.Build(); HostFactory.Run(x => { x.Service <IssueService>(s => { s.ConstructUsing(obj => new IssueService()); s.WhenStarted(obj => obj.Start()); s.WhenStopped(obj => obj.Stop()); }); x.RunAsLocalSystem(); x.SetDescription("Issues microservice for MunkeyIssues"); x.SetDisplayName("MunkeyIssues Issues microservice"); x.SetServiceName("MunkeyIssuesIssuesService"); }); }
public AutoMapperFixture() { AutoMapperBuilder.Build(); }