示例#1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            container.Register<LocalityContext>();
            container.Register(typeof(IRepository<>), typeof(Repository<>) );
            container.Register<IUserService, UserService>();
            container.Register<IEventService, EventService>();
            container.Register<ITicketService, TicketService>();
            container.Register<IPaymentService, PaymentService>();

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
        }
示例#2
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.EnableCors(new MyCorsPolicyProvider());

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

            var container = new Container();

            ModelDI.Confiure(container);

            ServicesDI.Confiure(container);

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
        public static void Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            InitializeContainer(container);

            container.RegisterPerWebRequest(() =>
            {
                if (HttpContext.Current != null && HttpContext.Current.Items["owin.Enviroment"] == null && container.IsVerifying)
                {
                    return new OwinContext().Authentication;
                }

                return HttpContext.Current.GetOwinContext().Authentication;
            });

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
        public static void Register(HttpConfiguration config)
        {
            using (var container = new Container())
            {
                container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

                // Chamada dos módulos do Simple Injector
                BootStrapper.RegisterServices(container);

                // Necessário para registrar o ambiente do Owin que é dependência do Identity
                // Feito fora da camada de IoC para não levar o System.Web para fora
                container.RegisterPerWebRequest(() =>
                {
                    if (HttpContext.Current != null && HttpContext.Current.Items["owin.Environment"] == null && container.IsVerifying())
                    {
                        return new OwinContext().Authentication;
                    }
                    return HttpContext.Current.GetOwinContext().Authentication;

                });

                // This is an extension method from the integration package.
                container.RegisterWebApiControllers(config);

                container.Verify();

                GlobalConfiguration.Configuration.DependencyResolver =
                    new SimpleInjectorWebApiDependencyResolver(container);
            }
        }
示例#5
0
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();

            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            container.Register<IUserService, UserService>(Lifestyle.Scoped);
            container.Register<IUserRepository, UserHibernateRepository>(Lifestyle.Scoped);
            container.Register<IAssetService, AssetService>(Lifestyle.Scoped);
            container.Register<IAssetViewService, AssetViewService>(Lifestyle.Scoped);
            container.Register<IAssetRepository, AssetHibernateRepository>(Lifestyle.Scoped);
            container.Register<ITokenService, TokenService>(Lifestyle.Scoped);
            container.Register<ITokenRepository, TokenHibernateRepository>(Lifestyle.Scoped);

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

            // Web API configuration and services

            // Web API routes
            WebApiConfig.Register(GlobalConfiguration.Configuration);
        }
示例#6
0
        // Invoked once at startup to configure your application.
        public void Configuration(IAppBuilder builder)
        {
            var config = new HttpConfiguration();

            // Create the container as usual.
            var container = new Container();

            // Register your types, for instance using the RegisterWebApiRequest
            // extension from the integration package:
            container.RegisterWebApiRequest<IUserRepository, SqlUserRepository>();

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(config);

            container.Verify();

            config.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);

            config.MapHttpAttributeRoutes();
            //config.Routes.MapHttpRoute("Default", "", new { controller = "OEmbed" });

            //config.Formatters.XmlFormatter.UseXmlSerializer = true;
            //config.Formatters.Remove(config.Formatters.JsonFormatter);
            ////config.Formatters.Remove(config.Formatters.XmlFormatter);
            // config.Formatters.JsonFormatter.UseDataContractJsonSerializer = true;
            builder.UseWebApi(config);

            //builder.Use(async (context, next) => {
            //    using (container.BeginExecutionContextScope())
            //    {
            //        await next();
            //    }
            //});
        }
示例#7
0
        protected void Application_Start()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            // Register your types, for instance using the scoped lifestyle:
            container.Register<IUnitOfWork, UnitOfWork>(Lifestyle.Scoped);
            container.Register<IUserManager, UserManager>();
            container.Register<IOrderManagerEx, OrderManagerEx>();

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
            AutoMapperConfig.Configure();
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            log4net.Config.XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/Web.config")));
        }
示例#8
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var container = new Container();

            // Here comes container registrations
            #region Project-dependent injections
            container.RegisterWebApiRequest<IApplicationDbContext, ApplicationDbContext>();
            container.RegisterWebApiRequest<ApplicationDbContext>();

            container.RegisterWebApiRequest<IProductsService, ProductsService>();
            container.RegisterWebApiRequest<ICrudRepository<Product>, CrudRepository<Product>>();
            #endregion

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
        public static void Register(Container container)
        {
            container.Register(typeof (IQueryHandler<,>), new[] {typeof (IQueryHandler<,>).Assembly});
            container.Register(typeof (ICommandHandler<,>), new[] {typeof (ICommandHandler<,>).Assembly});

            container.RegisterCollection(typeof (IHyperMediaState), typeof (IHyperMediaState).Assembly);
            container.Register<IBoardState, BoardState>();
            container.Register<IBoardTaskState, BoardTaskState>();
            container.Register<IBoardColumnState, BoardColumnState>();

            container.Register<ISlugService, SlugService>();

            container.Register<ICommandDispatcher, CommandDispatcher>();
            container.Register<IQueryDispatcher, QueryDispatcher>();
            container.Register<ILinkFactory, LinkFactory>();
            container.Register<IHyperMediaFactory, HyperMediaFactory>();
            container.Register<IMappingService, MappingService>();

            container.RegisterWebApiRequest<IDataContext, DataContext>();

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.EnableHttpRequestMessageTracking(GlobalConfiguration.Configuration);
            container.RegisterSingleton<IRequestMessageProvider>(new RequestMessageProvider(container));

            container.Register<IValidator<Board>, BoardValidator>();
            container.Register<IValidator<BoardColumn>, BoardColumnValidator>();
            container.Register<IValidator<BoardTask>, BoardTaskValidator>();

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
        public static Container RegisterComponents()
        {
            // Set up the localdb data directory.
            var dataDirectory = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
            dataDirectory = Path.Combine(dataDirectory, "..\\..\\Database");
            dataDirectory = Path.GetFullPath(dataDirectory);
            AppDomain.CurrentDomain.SetData("DataDirectory", dataDirectory);

            // Create the container and register all the api controllers.
            var container = new Container();
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            // Model.Api Registrations
            container.Register<IAuthenticationService, AuthenticationService>();
            container.Register<IChannelService, ChannelService>();
            container.Register<IUserItemService, UserItemService>();
            container.Register<IRegistrationService, RegistrationService>();

            // Model.Persistence Registations
            container.Register(
                () => new SqlHelper(ConfigurationManager.AppSettings["persistence"]),
                Lifestyle.Singleton);
            container.Register<IRssService, RssService>();
            container.Register<IUserService, UserService>();

            // Verify that everything is wired up properly.
            container.Verify();

            // Register the container as the default dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

            return container;
        }
示例#11
0
 public static void Initialize(HttpConfiguration config)
 {
     Container container = new Container();
     container.RegisterWebApiRequest<IContactsDbContext>(() => new ContactsDbContext());
     container.RegisterWebApiControllers(config);
     container.Verify();
     config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
 }
 public void ConfigureWebApi()
 {
     container = new Container();
     InitializeContainer(container);
     container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
     container.Verify();
     GlobalConfiguration.Configuration.DependencyResolver =
         new SimpleInjectorWebApiDependencyResolver(container);
 }
        public static void Configure(HttpConfiguration config, Container container)
        {
            container.RegisterWebApiControllers(config, typeof(WebApiConfig).Assembly);

            config.MapHttpAttributeRoutes();
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            config.Formatters.JsonFormatter.UseDataContractJsonSerializer = false;
            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            config.EnsureInitialized();
        }
示例#14
0
        public static void Build(IAppBuilder app, Container container = null) {
            var loggerFactory = Settings.Current.GetLoggerFactory();
            var logger = loggerFactory.CreateLogger(nameof(AppBuilder));

            if (container == null)
                container = CreateContainer(loggerFactory, logger);

            var config = new HttpConfiguration();
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;

            SetupRouteConstraints(config);
            container.RegisterWebApiControllers(config);

            VerifyContainer(container);

            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

            var contractResolver = container.GetInstance<IContractResolver>();
            var exceptionlessContractResolver = contractResolver as ExceptionlessContractResolver;
            exceptionlessContractResolver?.UseDefaultResolverFor(typeof(Connection).Assembly);
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = contractResolver;

            config.Services.Add(typeof(IExceptionLogger), new FoundatioExceptionLogger(loggerFactory.CreateLogger<FoundatioExceptionLogger>()));
            config.Services.Replace(typeof(IExceptionHandler), container.GetInstance<ExceptionlessReferenceIdExceptionHandler>());

            config.MessageHandlers.Add(container.GetInstance<XHttpMethodOverrideDelegatingHandler>());
            config.MessageHandlers.Add(container.GetInstance<EncodingDelegatingHandler>());
            config.MessageHandlers.Add(container.GetInstance<AuthMessageHandler>());

            // Throttle api calls to X every 15 minutes by IP address.
            config.MessageHandlers.Add(container.GetInstance<ThrottlingHandler>());

            // Reject event posts in orgs over their max event limits.
            config.MessageHandlers.Add(container.GetInstance<OverageHandler>());

            EnableCors(config, app);

            container.Bootstrap(config);
            container.Bootstrap(app);

            app.UseWebApi(config);
            SetupSignalR(app, container, loggerFactory);
            SetupSwagger(config);

            if (Settings.Current.WebsiteMode == WebsiteMode.Dev)
                Task.Run(async () => await CreateSampleDataAsync(container));
            
            var context = new OwinContext(app.Properties);
            var token = context.Get<CancellationToken>("host.OnAppDisposing");
            RunMessageBusBroker(container, logger, token);
            RunJobs(container, loggerFactory, logger, token);

            logger.Info("Starting api...");
        }
示例#15
0
        public static void Initialize()
        {
            // Create the container as usual.
            var container = new Container();

            //setup logger
            container.RegisterSingle<ILogger>(() =>
                new LoggerConfiguration()
                .WriteTo.ColoredConsole()
                .WriteTo.Trace()
                .CreateLogger()
            );
            
            //instagram config for InstaSharp
            container.RegisterSingle<InstagramConfig>(() =>
            {
                var clientId = ConfigurationManager.AppSettings["clientId"];
                var clientSecret = ConfigurationManager.AppSettings["clientSecret"];
                var callbackUri = ConfigurationManager.AppSettings["callbackUri"];
                var redirectUri = ConfigurationManager.AppSettings["redirectUri"];

                var icfg = new InstagramConfig(clientId, clientSecret);
                icfg.CallbackUri = callbackUri;
                icfg.RedirectUri = redirectUri;
                return icfg;
            }
            );

            // Azure storage account
            container.RegisterSingle(() =>
            {
                var connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];
                return CloudStorageAccount.Parse(connectionString);
            });

            // Azure table client
            container.RegisterSingle(() => container.GetInstance<CloudStorageAccount>().CreateCloudTableClient());

            //register our tablesets, in this case we only have one
            container.RegisterWebApiRequest<ITableSet<RealtimeSubscription>>(() =>
                new TableSet<RealtimeSubscription>(container.GetInstance<CloudTableClient>())
                );

            //register repositories
            container.Register<ISubscriptionRepository, SubscriptionRepository>(Lifestyle.Singleton);

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
示例#16
0
        public static SimpleInjector.Container ApiInitialize()
        {
            _container = new SimpleInjector.Container();

            _container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
            _container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            Register();

            return(_container);
        }
        /// <summary>Initialize the container and register it as MVC3 Dependency Resolver.</summary>
        public static void Initialize()
        {
            // Did you know the container can diagnose your configuration?
            // Go to: https://simpleinjector.org/diagnostics
            var container = new Container();
            InitializeContainer(container);

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.Verify();
            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
示例#18
0
文件: Startup.cs 项目: denholms/LSCS
        private void InjectDependencies(HttpConfiguration config)
        {
            var container = new Container();

            container.RegisterSingle(() => ChecklistRepository);
            container.RegisterSingle(() => ControllerConfiguration);

            container.RegisterWebApiControllers(config);
            container.Verify();

            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
        private static void Register()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            DependencyConfig.Register(container);

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
        public static Container Initialize()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
            
            RegisterDependencies(container);
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            GlobalBackendConfiguration.ConfigureIoC(container);
            container.Verify();

            return container;
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BootstrapBundleConfig.RegisterBundles();

            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            container.RegisterSingleton<ILinqToLdapLogger>(new SimpleTextLogger());

            container.RegisterSingleton<ILdapConfiguration>(() =>
            {
                var config = new LdapConfiguration()
                    .MaxPageSizeIs(50)
                    .LogTo(container.GetInstance<ILinqToLdapLogger>());

                //Note the optional parameters available on AddMapping.
                //We can perform "late" mapping on certain values, 
                //even for auto and attribute based mapping.
                config.AddMapping(new OrganizationalUnitMap())
                      .AddMapping(new AttributeClassMap<User>());

                // I explicitly mapped User, but I can also let it 
                // get mapped the first time we query for users.
                // This only applies to auto and attribute-based mapping.

                config.ConfigurePooledFactory("directory.utexas.edu")
                      .AuthenticateBy(AuthType.Anonymous)
                      .MinPoolSizeIs(0)
                      .MaxPoolSizeIs(5)
                      .UsePort(389)
                      .ProtocolVersion(3);

                return config;
            });

            //simple context per request only when requested
            container.Register<IDirectoryContext>(() => container.GetInstance<ILdapConfiguration>().CreateContext(), Lifestyle.Scoped);

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
            
            container.Verify();
        }
示例#22
0
        private static Container BuildContainer()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            container.Register<IColorRepository, ColorRepository>(Lifestyle.Singleton);
            container.Register<IColorService, ColorService>();

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.Verify();
            return container;
        }
示例#23
0
        public static void Configure()
        {
            var container = new Container();

            BindingConfig.Bind(container);

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
示例#24
0
文件: Ioc.cs 项目: MrSercret/Void
        public static void Init()
        {
            var container = new Container();

            container.Register<IRestaurantService, RestaurantService>(Lifestyle.Transient);
            container.Register<IRestClient>(() => new RestClient(_apiUrl), Lifestyle.Transient);
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
示例#25
0
        private static void SetupContainer(HttpConfiguration config)
        {
            // Standard SimpleInjector Setup - See the following for more info:
            // http://simpleinjector.readthedocs.org/en/latest/webapiintegration.html
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
            container.RegisterWebApiControllers(config);

            RegisterDependencies(container);
            container.Verify();

            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
示例#26
0
        protected void Application_Start()
        {
            // Routing Stuff
            GlobalConfiguration.Configure(WebApiConfig.Register);

            // DI Stuff
            var container = new Container();
            //container.Register<IResumeRepository, ResumeRepository>(Lifestyle.Transient);
            container.Register<IResumeRepository, ResumeMongoRepository>(Lifestyle.Transient);
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.Verify();
            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); 
        }
示例#27
0
        public void ConfigureDependencyInjection(HttpConfiguration config, Container container)
        {
            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            RegisterHelper.Register(container);

            container.RegisterWebApiControllers(config);

            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            DomainEvent.Container = new DomainContainer(config.DependencyResolver);

            container.Verify();
        }
示例#28
0
        private static void InitializeContainer(Container container)
        {
            //container.Register<Security>(Lifestyle.Scoped);
            // container.Register(typeof(IUnitOfWork<>), typeof(UnitOfWork<>), Lifestyle.Scoped);
            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
            container.Register <ClinicasContext>(Lifestyle.Scoped);
            container.Register(typeof(IUnitOfWork <>), typeof(UnitOfWork <>), new ExecutionContextScopeLifestyle());
            container.RegisterWebApiRequest <IUserService, UserService>();
            container.Register <IPacienteRepository, PacienteRepository>();
            container.Register <IPacienteService, PacienteService>();

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
        }
示例#29
0
        public static void BuildWithContainer(IAppBuilder app, Container container) {
            if (container == null)
                throw new ArgumentNullException(nameof(container));
            
            Config = new HttpConfiguration();
            Config.Formatters.Remove(Config.Formatters.XmlFormatter);
            Config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
            
            SetupRouteConstraints(Config);
            container.RegisterWebApiControllers(Config);
            
            VerifyContainer(container);
            
            Config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

            var contractResolver = container.GetInstance<IContractResolver>();
            var exceptionlessContractResolver = contractResolver as ExceptionlessContractResolver;
            exceptionlessContractResolver?.UseDefaultResolverFor(typeof(Connection).Assembly);
            Config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = contractResolver;

            Config.Services.Add(typeof(IExceptionLogger), new FoundatioExceptionLogger());
            Config.Services.Replace(typeof(IExceptionHandler), container.GetInstance<ExceptionlessReferenceIdExceptionHandler>());

            Config.MessageHandlers.Add(container.GetInstance<XHttpMethodOverrideDelegatingHandler>());
            Config.MessageHandlers.Add(container.GetInstance<EncodingDelegatingHandler>());
            Config.MessageHandlers.Add(container.GetInstance<AuthMessageHandler>());

            // Throttle api calls to X every 15 minutes by IP address.
            Config.MessageHandlers.Add(container.GetInstance<ThrottlingHandler>());

            // Reject event posts in orgs over their max event limits.
            Config.MessageHandlers.Add(container.GetInstance<OverageHandler>());

            EnableCors(Config, app);

            container.Bootstrap(Config);
            container.Bootstrap(app);
            Mapper.Configuration.ConstructServicesUsing(container.GetInstance);
            
            app.UseWebApi(Config);
            SetupSignalR(app, container);
            SetupSwagger(Config);
            
            if (Settings.Current.WebsiteMode == WebsiteMode.Dev)
                Task.Run(async () => await CreateSampleDataAsync(container));
            
            RunJobs(app);
            Logger.Info().Message("Starting api...").Write();
        }
        public static void Register(HttpConfiguration config)
        {
            Container = new SimpleInjector.Container();

            //Async Scope designed for Web API.
            Container.Options.DefaultLifestyle = new SimpleInjector.Lifestyles.AsyncScopedLifestyle();

            //Register Data Worker (UoW)
            Container.Register <IDataWorker, DataWorker>();

            Container.RegisterWebApiControllers(config);
            Container.Verify();

            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(Container);
        }
       public static void Initialize()
       {
           // Create IoC container
           var container = new Container();
 
           // Register dependencies
           InitializeContainer(container);
           container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
      
           // Verify registrations
           container.Verify();
           
           // Set Web API dependency resolver
           GlobalConfiguration.Configuration.DependencyResolver =
               new SimpleInjectorWebApiDependencyResolver(container);
       }
示例#32
0
        protected void Application_Start()
        {
            _container = new Container();

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            RegisterCommands(_container);

            _container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            _container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(_container);
        }
        private static void ConfigWebApi()
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();
            Common.SimpleInjectorCommon.RegisterItems(container, Lifestyle.Scoped);
            // Register your types, for instance using the scoped lifestyle:
            //container.Register<IUserRepository, SqlUserRepository>(Lifestyle.Scoped);

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            var container = new SimpleInjector.Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            container.Register <EntityContext>(() => new EntityContext(), Lifestyle.Scoped);

            container.Register <CustomerRepository>(Lifestyle.Transient);

            container.Register <CustomerService>(Lifestyle.Transient);

            container.Register <CustomerCommandHandler>(Lifestyle.Transient);

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
示例#35
0
        public static void Register(HttpConfiguration config)
        {
            var container = new SimpleInjector.Container();

            container.Options.DefaultScopedLifestyle = new SimpleInjector.Lifestyles.AsyncScopedLifestyle();


            container.Register <IAccountService, AccountService>(Lifestyle.Transient);
            container.RegisterInstance <ILogger>(LogManager.GetCurrentClassLogger());
            container.RegisterWebApiControllers(config);
            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

            config.Filters.Add(new ExceptionFilter());

            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );
        }
示例#36
0
        protected void Application_Start()
        {
            // Create the container as usual.
            var container = new SimpleInjector.Container();

            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            // Register your types, for instance using the scoped lifestyle:
            container.Register <IDatabaseFactory, DatabaseFactory>(Lifestyle.Scoped);
            container.Register <IUnitOfWork, UnitOfWork>();
            container.Register <IAssignmentRepository, AssignmentRepository>();
            container.Register <IStudentRepository, StudentRepository>();
            container.Register <IProjectRepository, ProjectRepository>();

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);

            GlobalConfiguration.Configure(WebApiConfig.Register);
        }
示例#37
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var container = new SimpleInjector.Container();

            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            container.Register <ICacheService, CacheService>(Lifestyle.Singleton);

            container.Register <IOrderService, OrderService>(Lifestyle.Scoped);

            container.RegisterDecorator(typeof(IOrderService), typeof(OrderCacheService));

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjector.Integration.WebApi.SimpleInjectorWebApiDependencyResolver(container);
        }
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;

            // get decimal places for decimal input in api
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Culture = new CultureInfo(string.Empty)
            {
                NumberFormat = new NumberFormatInfo
                {
                    CurrencyDecimalDigits = 3
                }
            };

            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new DecimalConverter());



            // Create the container as usual.
            var container = new SimpleInjector.Container();

            container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle();

            InitializeRepositories(container);

            // This is an extension method from the integration package.
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(container);
        }
 /// <summary>
 /// Registers the Web API <see cref="IHttpController"/> types that available for the application. This
 /// method uses the configured <see cref="IHttpControllerTypeResolver"/> to determine which controller
 /// types to register.
 /// </summary>
 /// <param name="container">The container the controllers should be registered in.</param>
 /// <param name="configuration">The <see cref="HttpConfiguration"/> to use to get the Controller
 /// types to register.</param>
 /// <param name="assemblies">The assemblies to search.</param>
 /// <exception cref="ArgumentNullException">Thrown when one of the arguments is a null
 /// reference (Nothing in VB).</exception>
 public static void RegisterWebApiControllers(this Container container, HttpConfiguration configuration,
                                              params Assembly[] assemblies)
 {
     container.RegisterWebApiControllers(configuration, (IEnumerable <Assembly>)assemblies);
 }