public FunqControllerFactory(Container container)
        {
            this.funqBuilder = new ContainerResolveCache(container);

            // Also register all the controller types as transient
            var controllerTypes =
                (from type in Assembly.GetCallingAssembly().GetTypes()
                 where typeof(IController).IsAssignableFrom(type)
                 select type).ToList();

            container.RegisterAutoWiredTypes(controllerTypes);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunqControllerFactory" /> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <param name="assemblies">The assemblies to reflect for IController discovery.</param>
        public FunqControllerFactory(Container container, params Assembly[] assemblies)
		{
			this.funqBuilder = new ContainerResolveCache(container);

            // aggregate the local and external assemblies for processing (unless ignored)
            IEnumerable<Assembly> targetAssemblies = assemblies.Concat(new[] { Assembly.GetCallingAssembly() });

            foreach (var assembly in targetAssemblies)
            {
                // Also register all the controller types as transient
                var controllerTypes =
                    (from type in assembly.GetTypes()
                     where typeof(IController).IsAssignableFrom(type)
                     select type).ToList();

                container.RegisterAutoWiredTypes(controllerTypes);
            }
		}
Ejemplo n.º 3
0
        public override void Configure(Container container)
        {
            //Plugins.RemoveAll(x => x is MetadataFeature);
            Plugins.Add(new CorsFeature());
            Plugins.Add(new SwaggerFeature());
            Plugins.Add(new ValidationFeature());
            Plugins.Add(new PostmanFeature());

            var config = new AppConfig();

            config.ReadWriteApiKeys.AddRange(ConfigurationManager.AppSettings["apiKeys"].Split(new[] {','}));

            container.Register(config);

            GlobalRequestFilters.Add((req, res, requestDto) =>
            {
                if (requestDto.GetType() != typeof (CreateCrawler) &&
                    req.Verb.ContainsAny(new[] {"DELETE", "PUT", "POST"}))
                {
                    var keyValidator = new ApiKeyAttribute();
                    keyValidator.Execute(req, res, requestDto);
                }
            });

            SetConfig(new HostConfig
            {
                DefaultRedirectPath = "/swagger-ui/"
            });

            container.RegisterAutoWiredAs<UriRequestRunner, IScraperRequestRunner>();
            container.RegisterAutoWiredAs<WebScraper, IScraper>();
            container.RegisterAutoWiredAs<CrawlWebRunner, ICrawlRunner>();

            container.RegisterAutoWiredTypes(new[]
            {typeof (CrawlerValidator), typeof (LeagueEngine), typeof (LeagueServices)});

            container.RegisterValidators(typeof(CreateSeasonValidator).Assembly);

            //container.RegisterAutoWired<GameEngine>().ReusedWithin(ReuseScope.Container);

            container.Register<IDbConnectionFactory>(
                new OrmLiteConnectionFactory(HttpContext.Current.Server.MapPath("~/App_Data/leaguedata.sqlite"),
                    SqliteDialect.Provider));

            //container.Register<IDbConnectionFactory>(
            //    new OrmLiteConnectionFactory(
            //    "Server=127.0.0.1;Port=5432;User Id=postgres;Password=test123;Database=testDb;Pooling=true;MinPoolSize=0;MaxPoolSize=200",
            //    PostgreSqlDialect.Provider));

            using (var db = container.Resolve<IDbConnectionFactory>().Open())
            {
                db.CreateTableIfNotExists<Season>();
                db.CreateTableIfNotExists<Division>();
                db.CreateTableIfNotExists<Server>();
                db.CreateTableIfNotExists<Crawler>();
                db.CreateTableIfNotExists<Participant>();
                db.CreateTableIfNotExists<Game>();
                db.CreateTableIfNotExists<Rune>();
            }

            OrmLiteConfig.InsertFilter = (dbCmd, row) =>
            {
                var auditRow = row as IAudit;
                if (auditRow != null)
                    auditRow.CreatedDate = auditRow.ModifiedDate = DateTime.UtcNow;
            };

            OrmLiteConfig.UpdateFilter = (dbCmd, row) =>
            {
                var auditRow = row as IAudit;
                if (auditRow != null)
                    auditRow.ModifiedDate = DateTime.UtcNow;
            };

            container.Resolve<LeagueEngine>().Start();
        }