Exemplo n.º 1
0
        public static void Init(IAppHost appHost, Func <IAuthSession> sessionFactory, params IAuthProvider[] authProviders)
        {
            if (authProviders.Length == 0)
            {
                throw new ArgumentNullException("authProviders");
            }

            DefaultOAuthProvider = authProviders[0].Provider;
            DefaultOAuthRealm    = authProviders[0].AuthRealm;

            AuthProviders = authProviders;
            if (sessionFactory != null)
            {
                CurrentSessionFactory = sessionFactory;
            }

            var test = appHost != null;

            if (test)
            {
                appHost.RegisterService <AuthService>();
                appHost.RegisterService <AssignRolesService>();
                appHost.RegisterService <UnAssignRolesService>();
                SessionFeature.Init(appHost);
            }
        }
Exemplo n.º 2
0
        public static void Init(IAppHost appHost, Func <IAuthSession> sessionFactory, params AuthConfig[] authConfigs)
        {
            if (authConfigs.Length == 0)
            {
                throw new ArgumentNullException("authConfigs");
            }

            DefaultOAuthProvider = authConfigs[0].Provider;
            DefaultOAuthRealm    = authConfigs[0].AuthRealm;

            AuthConfigs    = authConfigs;
            SessionFactory = sessionFactory;
            appHost.RegisterService <AuthService>();

            SessionFeature.Init(appHost);
        }
Exemplo n.º 3
0
            public override void Configure(Container container)
            {
                JsConfig.EmitCamelCaseNames = true;

                this.RequestFilters.Add((req, res, dto) => {
                    var requestFilter = dto as RequestFilter;
                    if (requestFilter != null)
                    {
                        res.StatusCode = requestFilter.StatusCode;
                        if (!requestFilter.HeaderName.IsNullOrEmpty())
                        {
                            res.AddHeader(requestFilter.HeaderName, requestFilter.HeaderValue);
                        }
                        res.Close();
                    }

                    var secureRequests = dto as IRequiresSession;
                    if (secureRequests != null)
                    {
                        res.ReturnAuthRequired();
                    }
                });

                this.Container.Register <IDbConnectionFactory>(c =>
                                                               new OrmLiteConnectionFactory(
                                                                   "~/App_Data/db.sqlite".MapHostAbsolutePath(),
                                                                   SqliteOrmLiteDialectProvider.Instance)
                {
                    ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                });

                this.Container.Register <ICacheClient>(new MemoryCacheClient());
                //this.Container.Register<ICacheClient>(new BasicRedisClientManager());

                ConfigureAuth(container);

                //this.Container.Register<ISessionFactory>(
                //    c => new SessionFactory(c.Resolve<ICacheClient>()));

                var dbFactory = this.Container.Resolve <IDbConnectionFactory>();

                dbFactory.Exec(dbCmd => dbCmd.CreateTable <Movie>(true));
                ModelConfig <Movie> .Id(x => x.Title);

                Routes
                .Add <Movies>("/custom-movies", "GET")
                .Add <Movies>("/custom-movies/genres/{Genre}")
                .Add <Movie>("/custom-movies", "POST,PUT")
                .Add <Movie>("/custom-movies/{Id}")
                .Add <MqHostStats>("/mqstats");

                var resetMovies = this.Container.Resolve <ResetMoviesService>();

                resetMovies.Post(null);

                ValidationFeature.Init(this);
                container.RegisterValidators(typeof(CustomersValidator).Assembly);

                SessionFeature.Init(this);

                //var onlyEnableFeatures = Feature.All.Remove(Feature.Jsv | Feature.Soap);
                SetConfig(new EndpointHostConfig {
                    //EnableFeatures = onlyEnableFeatures,
                    DebugMode = true,                     //Show StackTraces for easier debugging
                });

                var redisManager = new BasicRedisClientManager();
                var mqHost       = new RedisMqHost(redisManager, 2, null);

                mqHost.RegisterHandler <Reverse>(this.Container.Resolve <ReverseService>().Execute);
                mqHost.Start();

                this.Container.Register((IMessageService)mqHost);
            }