Пример #1
0
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();
            var constraintResolver   = new DefaultInlineConstraintResolver()
            {
                ConstraintMap =
                {
                    ["apiVersion"] = typeof(ApiVersionRouteConstraint)
                }
            };

            config.MapHttpAttributeRoutes(constraintResolver);

            config.AddApiVersioning();

            app.UseWebApi(config);

            config
            .EnableSwagger(c =>
            {
                c.SingleApiVersion("v1", "Diff API - Andrew Signori");
                c.IncludeXmlComments($"{System.AppDomain.CurrentDomain.BaseDirectory}\\App_Data\\Diff.XML");
            })
            .EnableSwaggerUi(c => c.DocExpansion(DocExpansion.List));

            config.DependencyResolver = DependencyRegistrations.GetDependencyResolver();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            DependencyRegistrations.Register(services);

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));
            services.AddDefaultIdentity <ApplicationUser>()
            .AddDefaultUI(UIFramework.Bootstrap4)
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services
            .AddJsEngineSwitcher(options => options.DefaultEngineName = ChakraCoreJsEngine.EngineName)
            .AddChakraCore(s => { s.DisableFatalOnOOM = true; });
            services.AddReact();
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(x =>
            {
                x.SerializerSettings.ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy()
                };
            });
        }
Пример #3
0
        public void Initialize()
        {
            IDependencyResolver dependencyResolver = DependencyRegistrations.GetDependencyResolver();

            // While creating the controller for tests we could use a different repository speficic
            // for tests, but here the ideia is use the same for the exercise purposes.
            _diffController = (DiffController)dependencyResolver.GetService(typeof(DiffController));
            _repository     = (IRepository)dependencyResolver.GetService(typeof(IRepository));
            _repository.ClearData();
        }
Пример #4
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            NinjectModule registrations = new DependencyRegistrations();
            IKernel       kernel        = new StandardKernel(registrations);

            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

            Database.SetInitializer(new DatabaseInitializer());
        }
Пример #5
0
        static void Main(string[] args)
        {
            string buffer = Console.In.ReadToEnd();

            var             serviceProvider = DependencyRegistrations.ConfigureServices();
            FunctionHandler f = (FunctionHandler)serviceProvider.GetService(typeof(FunctionHandler));

            string responseValue = f.Handle(buffer);

            if (responseValue != null)
            {
                Console.Write(responseValue);
            }
        }
Пример #6
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RouteConfig.RegisterRoutes(RouteTable.Routes);
            GlobalConfiguration.Configure(WebApiConfig.Register);

            IUnityContainer container = DependencyRegistrations.Register();

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));

            FilterProviders.Providers.Remove(FilterProviders.Providers.OfType <FilterAttributeFilterProvider>().First());
            FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));

            GlobalFilters.Filters.Add(new ErrorHandler(container.Resolve <IErrorService>()));

            Vault.Init();
        }
Пример #7
0
        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();

            try
            {
                kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel);
                kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>();
                DependencyRegistrations.RegisterControllerDependencies(kernel);

                return(kernel);
            }
            catch
            {
                kernel.Dispose();

                throw;
            }
        }
Пример #8
0
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Formatters.Clear();
            config.Formatters.Add(new JsonMediaTypeFormatter());

            IUnityContainer container = DependencyRegistrations.Register();

            config.DependencyResolver = new WebApiUnityDependencyResolver(container);

            List <IFilterProvider> filterProviders       = config.Services.GetFilterProviders().ToList();
            IFilterProvider        defaultFilterProvider = filterProviders.Single(p => p is ActionDescriptorFilterProvider);

            config.Services.Remove(typeof(IFilterProvider), defaultFilterProvider);
            config.Services.Add(typeof(IFilterProvider), new WebApiUnityFilterProvider(container));
        }
 protected TResolveFor Resolve <TResolveFor>()
 {
     return(DependencyRegistrations.Resolve <TResolveFor>(DependencyFakes));
 }
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     DependencyRegistrations.Register(services);
 }