Beispiel #1
0
        //public override RouteAttribute[] GetRouteAttributes(Type requestType)
        //{
        //    var routes = base.GetRouteAttributes(requestType);
        //    routes.Each(x => x.Path = "/v1" + x.Path);
        //    return routes;
        //}

        //public override IDbConnection GetDbConnection(IRequest req = null)
        //{
        //    //If an API Test Key was used return DB connection to TestDb instead:
        //    return req.GetApiKey()?.Environment == "test"
        //        ? TryResolve<IDbConnectionFactory>().OpenDbConnection("Agency_Test")
        //        : base.GetDbConnection(req);
        //}

        private void ConfigureDb(Container container, IAppSettings appSettings)
        {
            var dbFactory = new OrmLiteConnectionFactory(
                ConfigUtils.GetConnectionString("Agency"), SqlServerDialect.Provider);

            container.Register <IDbConnectionFactory>(dbFactory);
            //dbFactory.RegisterConnection("Agency_Test", ConfigUtils.GetConnectionString("Agency_Test"), SqlServerDialect.Provider);

            //Repositories
            container.RegisterAutoWiredType(typeof(ITicket), typeof(Ticket));
            container.RegisterAutoWiredType(typeof(ITicketAgent), typeof(TicketAgent));
            container.RegisterAutoWiredType(typeof(IOperatorAgent), typeof(OperatorAgent));
            container.RegisterAutoWiredType(typeof(ITicketStatus), typeof(TicketStatus));
            container.RegisterAutoWiredType(typeof(IReceipt), typeof(Receipt));

            var repo = new OrmLiteTicketRepository(dbFactory);

            container.Register <ITicketRepository>(c => repo);
            repo.InitSchema();

            var repo2 = new OrmLiteTicketAgentRepository(dbFactory);

            container.Register <ITicketAgentRepository>(c => repo2);

            var repo3 = new OrmLiteOperatorAgentRepository(dbFactory);

            container.Register <IOperatorAgentRepository>(c => repo3);
            repo3.InitSchema();

            var repo4 = new RedisTicketStatusRepository(container.Resolve <IRedisClientsManager>());

            container.Register <ITicketStatusRepository>(c => repo4);

            var repo5 = new OrmLiteReceiptRepository(dbFactory);

            container.Register <IReceiptRepository>(c => repo5);
            repo3.InitSchema();
        }
Beispiel #2
0
        private void ConfigureDb(Container container, IAppSettings appSettings)
        {
            var connections = appSettings.Get <Dictionary <string, string> >("connectionStrings");

            var dbFactory = new OrmLiteConnectionFactory(connections.GetValueOrDefault("Agency"), MySqlDialect.Provider);

            container.Register <IDbConnectionFactory>(dbFactory);

            //Repositories
            container.RegisterAutoWiredType(typeof(IOperatorAgent), typeof(OperatorAgent));

            var repo3 = new OrmLiteOperatorAgentRepository(dbFactory);

            container.Register <IOperatorAgentRepository>(c => repo3);
            repo3.InitSchema();
        }