예제 #1
0
        static IContainer InitApp()
        {
            var builder = new ConfigurationBuilder()
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true);

            var configuration = builder.Build();

            var svcCollection = new ServiceRegistry();

            // Add Dave services
            svcCollection.AddDave(configuration);

            // Add Dave logging
            svcCollection.AddDaveLoggerSerilog();

            // Add __DT_PROJECT_NAME registrations
            svcCollection.Add__DT_PROJECT_NAME();

            var container = new Container(svcCollection);

            // Create Service Provider
            var serviceProvider = container.ServiceProvider;

            // Set current Program Logger
            Log = serviceProvider.GetService <ILogger <Program> >();

            // create Dave
            var identity = configuration.GetValue <string>("FakeIdentity");

            try {
                if (identity != null)
                {
                    serviceProvider.CreateDave(c => c.DisableLogAccess().IdentifyUser(() => identity));
                }
                else
                {
                    serviceProvider.CreateDave();
                }
            } catch (Exception ex) {
                ShowError(ex);
                Environment.Exit(99);
            }

            return(container);
        }
예제 #2
0
파일: Startup.cs 프로젝트: vgmr/dev-toolkit
        public void ConfigureContainer(ServiceRegistry services)
        {
            // Add  Dave
            services.AddDave(Configuration);

            // Add Dave Logging (serilog)
            services.AddDaveLoggerSerilog(builder =>
            {
                if (HostingEnvironment.IsDevelopment())
                {
                    builder.DiagnoticDebug = Configuration.GetValue <bool>("AddDiagnosticDebug", false);
                }
            });

            services.Add__DT_PROJECT_NAME();

            services.AddCors();

            services.AddMvc(m =>
            {
                // uncomment to use YodaServiceResult
                //m.AddYodaService();
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            // Add Swagger integration
            services.AddSwaggerGen(options =>
            {
                options.OperationFileResultFilter();
                options.MapType <Stream>(() => new Schema {
                    Type = "file"
                });

                options.SwaggerDoc("v1", new Info
                {
                    Title       = "__DT_PROJECT_NAME",
                    Version     = "v1",
                    Description = "__DT_PROJECT_NAME Web Api"
                });
                options.CustomOperationIds(ad => $"{ad.ActionDescriptor.RouteValues["controller"]}_{ad.ActionDescriptor.RouteValues["action"]}");
                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                options.IncludeXmlComments(xmlPath);
            });
        }