Esempio n. 1
0
        public override void Configure(Funq.Container container)
        {
            var host = ConfigurationManager.AppSettings.Get("PaypalWebsiteURL");

            SetConfig(new EndpointHostConfig
            {
                DebugMode = false, // Debugmode for stacktrace

                GlobalResponseHeaders =
                {
                    { "Access-Control-Allow-Origin",  "*"                               },
                    { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" }
                },
                //EnableFeatures = Feature.All.Remove(GetDisabledFeatures()),
                EnableFeatures = ServiceStack.ServiceHost.Feature.All,
                //RestrictAllCookiesToDomain = "www.photobookmart.com"
                //ServiceStackHandlerFactoryPath = "api",
                //AppendUtf8CharsetOnContentTypes = new HashSet<string> { ContentType.Html },
            });

            //Set JSON web services to return idiomatic JSON camelCase properties
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = false;

            //Register a external dependency-free
            //container.Register<ICacheClient>(new MemoryCacheClient());

            /* TODO:...
             * var redis_host = ConfigurationManager.AppSettings.Get("RedisHost");
             * var redis_db = long.Parse(ConfigurationManager.AppSettings.Get("RedisDBVersion"));
             * var pooled_redis = new PooledRedisClientManager(redis_db, redis_host);
             * pooled_redis.NamespacePrefix = System.Reflection.Assembly.GetExecutingAssembly().FullName;
             * container.Register<IRedisClientsManager>(c => pooled_redis);
             * container.Register<ICacheClient>(c =>
             *  (ICacheClient)c.Resolve<IRedisClientsManager>()
             *  .GetCacheClient())
             *  .ReusedWithin(Funq.ReuseScope.None);*/


            //Enable Authentication an Registration
            VMCCredenticalsProvider authProvider = new VMCCredenticalsProvider();

            Plugins.Add(new SessionFeature());
            AuthFeature authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] {
                authProvider, new BasicAuthProvider()
            });

            //authFeature.ServiceRoutes.Clear(); // we clear all routes
            Plugins.Add(authFeature);
            Plugins.Add(new RegistrationFeature());


            //Create a DB Factory configured to access the UserAuth SQL Server DB
            dbFactory = GetDbConnectionFromConfig();
            //container.Register(c => GetDbConnectionFromConfig()).ReusedWithin(Funq.ReuseScope.Container);
            //var dbConnection = container.Resolve<OrmLiteConnectionFactory>();
            container.Register <IDbConnectionFactory>(dbFactory);
            //container.Register(c => GetDbConnectionFromConfig()).ReusedWithin(Funq.ReuseScope.Request);

            // register db connection
            //container.Register(c => dbFactory.OpenDbConnection()).ReusedWithin(Funq.ReuseScope.Container);
            DatabaseConnection = dbFactory.OpenDbConnection();
            container.Register(c => dbFactory.OpenDbConnection()).ReusedWithin(Funq.ReuseScope.Container);
            //container.Register<IDbConnection>(DatabaseConnection);
            // caching  - TODO: later must change to ORMLiteCache
            //container.RegisterAs<OrmLiteCacheClient, ICacheClient>();
            //Create 'CacheEntry' RDBMS table if it doesn't exist already
            //container.Resolve<ICacheClient>().InitSchema();
            // end of caching register

            // create tables
            ModelBase.InitDbTable(ConfigurationManager.AppSettings.Get("AdminUserNames"), true, true);

            //container.RegisterAutoWired<IDbConnection>();
            //container.Register<IDbConnectionFactory>(dbConnection);
            // Register ORM Lite Authentication Repository with our Authentication
            var userRep = new ABORMLiteAuthRepository(dbFactory);

            container.Register <IAuthProvider>(authProvider);
            container.Register <IUserAuthRepository>(userRep);

            //Configure Custom User Defined REST Paths for your services
            ConfigureServiceRoutes();

            //Set MVC to use the same Funq IOC as ServiceStack
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
            //ServiceStackController.CatchAllController = reqCtx => container.TryResolve<HomeController>();
        }