Esempio n. 1
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            var jsonFormatter = new JsonMediaTypeFormatter();

            config.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(jsonFormatter));

            var settings = jsonFormatter.SerializerSettings;

            settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            settings.Formatting            = Formatting.Indented;
            settings.ContractResolver      = new CamelCasePropertyNamesContractResolver();

            // Configure Web API with the dependency resolver
            GlobalConfiguration.Configuration.DependencyResolver = AutofacBootStrapper.AutofacWebApiDependencyResolver();

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
        // 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.AddMvc();

            var bootStrapper = new AutofacBootStrapper();
            var builder      = bootStrapper.GetBuilder();

            builder.Populate(services);

            var container = bootStrapper.GetContainer();

            return(container.Resolve <IServiceProvider> ());
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var bootStrapper = new AutofacBootStrapper();
            var stockService = bootStrapper.GetContainer().Resolve <IStockService> ();
            var result       = Parser.Default.ParseArguments <CLIOptions> (args);

            result.MapResult(o => {
                var fullPath = Path.GetFullPath(o.InputFile);
                if (File.Exists(fullPath))
                {
                    stockService.ImportStocksByCSVFile(fullPath);
                }
                return(0);
            }, errs => 1);
        }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddCors();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "JetAnotherEMS API", Version = "v1"
                });
            });

            AddAutoMapperSetup(services);
            AddAuthorization(services);
            AddAuthentication(services);

            var builder = new ContainerBuilder();

            builder.RegisterType <HttpContextAccessor>().As <IHttpContextAccessor>();
            builder.RegisterType <ClaimsRequirementHandler>().As <IAuthorizationHandler>();

            builder.Populate(services);
            AutofacBootStrapper.RegisterServices(builder);

            // DB Contexts
            builder.RegisterType <ApplicationContextDbFactory>().AsSelf().AsImplementedInterfaces();

            builder.RegisterType <EventStoreSQLContext>().InstancePerLifetimeScope();
            builder.RegisterType <JetAnotherEmsContext>().InstancePerLifetimeScope();

            builder.Register <ApplicationDbContext>(ctx =>
            {
                var factory = ctx.Resolve <IDesignTimeDbContextFactory <ApplicationDbContext> >();
                return(factory.CreateDbContext(new string[] { }));
            }).InstancePerLifetimeScope();

            ApplicationContainer = builder.Build();

            return(new AutofacServiceProvider(this.ApplicationContainer));
        }
 private void SetUp()
 {
     BootStrapper = new AutofacBootStrapper();
 }