public override void Configure(Container container)
        {
            container.Register<IDbConnectionFactory>(c =>
                new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));

            container.RegisterAs<OrmLiteCacheClient, ICacheClient>();
            container.Resolve<ICacheClient>().InitSchema();
        }
Exemplo n.º 2
1
        public override void Configure(Container container)
        {
            if (container == null)
                throw new ArgumentNullException("container");

            // Makes the a disk repository available to service implementations
            container.RegisterAs<DiskRepository,IDiskRepository>();

            #if DEBUG
            Trace.Listeners.Add(new ConsoleTraceListener(true));
            #endif
        }
Exemplo n.º 3
1
        private static void UseSmtpEmailer(Container container)
        {
            var appSettings = new AppSettings();

            //Use 'SmtpConfig' appSetting in Web.config if it exists otherwise use default config below:
            container.Register(appSettings.Get("SmtpConfig",
                new SmtpConfig {
                    Host = "smtphost",
                    Port = 587,
                    UserName = "******",
                    Password = "******"
                }));

            container.RegisterAs<SmtpEmailer, IEmailer>().ReusedWithin(ReuseScope.Request);
        }
Exemplo n.º 4
1
        public override void Configure(Container container)
        {
            LogManager.LogFactory = new ConsoleLogFactory();

            IAppSettings appSettings = new DictionarySettings(
                new Dictionary<string, string>
                    {
                        { "backup.history", "5" },
                        { "auth.api-keys", "1337"}
                    });

            container.Register(c => appSettings);
            container.RegisterAutoWired<IISManager>();
            container.RegisterAs<AppSettingsApiKeyValidator, IApiKeyValidator>();

            Plugins.Add(new RequestLogsFeature { RequiredRoles = null });
        }
Exemplo n.º 5
1
 private void ConfigureEmailer(Container container)
 {
     //If SmtpConfig exists, use real SMTP Emailer otherwise use simulated DbEmailer
     var smtpConfig = AppSettings.Get<EmailContacts.SmtpConfig>("SmtpConfig");
     if (smtpConfig != null)
     {
         container.Register(smtpConfig);
         container.RegisterAs<EmailContacts.SmtpEmailer, EmailContacts.IEmailer>().ReusedWithin(ReuseScope.Request);
     }
     else
     {
         container.RegisterAs<EmailContacts.DbEmailer, EmailContacts.IEmailer>().ReusedWithin(ReuseScope.Request);
     }
 }
Exemplo n.º 6
1
 /// <summary>
 /// Configure caching mechanism
 /// </summary>
 /// <param name="container">The DI / IoC container.</param>
 private void ConfigureCache(Container container)
 {
     // User OrmLite SQL database-backed persistent cache
     container.RegisterAs<OrmLiteCacheClient, ICacheClient>();
 }
Exemplo n.º 7
0
        private void ConfigureAuth(Container container)
        {
            //Enable and register existing services you want this host to make use of.
            //Look in Web.config for examples on how to configure your oauth providers, e.g. oauth.facebook.AppId, etc.
            var appSettings = new AppSettings();

            //Register all Authentication methods you want to enable for this web app.            
            Plugins.Add(new AuthFeature(
                () => new CustomUserSession(), //Use your own typed Custom UserSession type
                new IAuthProvider[] {
                    new CredentialsAuthProvider(),              //HTML Form post of UserName/Password credentials
                    new TwitterAuthProvider(appSettings),       //Sign-in with Twitter
                    new FacebookAuthProvider(appSettings),      //Sign-in with Facebook
                    new DigestAuthProvider(appSettings),        //Sign-in with Digest Auth
                    new BasicAuthProvider(),                    //Sign-in with Basic Auth
                    new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
                    new YahooOpenIdOAuthProvider(appSettings),  //Sign-in with Yahoo OpenId
                    new OpenIdOAuthProvider(appSettings),       //Sign-in with Custom OpenId
                    new GoogleOAuth2Provider(appSettings),      //Sign-in with Google OAuth2 Provider
                    new LinkedInOAuth2Provider(appSettings),    //Sign-in with LinkedIn OAuth2 Provider
                }));

#if HTTP_LISTENER
            //Required for DotNetOpenAuth in HttpListener 
            OpenIdOAuthProvider.OpenIdApplicationStore = new InMemoryOpenIdApplicationStore();
#endif

            //Provide service for new users to register so they can login with supplied credentials.
            Plugins.Add(new RegistrationFeature());

            //override the default registration validation with your own custom implementation
            container.RegisterAs<CustomRegistrationValidator, IValidator<Register>>();

            //Store User Data into the referenced SqlServer database
            container.Register<IAuthRepository>(c =>
                new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

            var authRepo = (OrmLiteAuthRepository)container.Resolve<IAuthRepository>(); //If using and RDBMS to persist UserAuth, we must create required tables
            if (appSettings.Get("RecreateAuthTables", false))
                authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
            else
                authRepo.CreateMissingTables();   //Create only the missing tables

            Plugins.Add(new RequestLogsFeature());
        }
Exemplo n.º 8
0
 private static void UseDbEmailer(Container container)
 {
     container.RegisterAs<DbEmailer, IEmailer>().ReusedWithin(ReuseScope.Request);
 }
Exemplo n.º 9
0
        private void ConfigureAuth(Container container)
        {
            //Enable and register existing services you want this host to make use of.
            //Look in Web.config for examples on how to configure your oauth providers, e.g. oauth.facebook.AppId, etc.
            var appSettings = new AppSettings();

            //Register all Authentication methods you want to enable for this web app.
            Plugins.Add(new AuthFeature(
                () => new CustomUserSession() {GalleryService = container.Resolve<IGalleryService>(), UserService = container.Resolve<IUserService>()},
                new IAuthProvider[] {
                    new CredentialsAuthProvider(),              //HTML Form post of UserName/Password credentials
                    new TwitterAuthProvider(appSettings),       //Sign-in with Twitter
                    new FacebookAuthProvider(appSettings),      //Sign-in with Facebook
                    new DigestAuthProvider(appSettings),        //Sign-in with Digest Auth
                    new BasicAuthProvider(),                    //Sign-in with Basic Auth
                    new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
                    new YahooOpenIdOAuthProvider(appSettings),  //Sign-in with Yahoo OpenId
                    new OpenIdOAuthProvider(appSettings),       //Sign-in with Custom OpenId
                }));

            //Provide service for new users to register so they can login with supplied credentials.
            Plugins.Add(new RegistrationFeature());

            //override the default registration validation with your own custom implementation
            container.RegisterAs<CustomRegistrationValidator, IValidator<Registration>>();

            //Create a DB Factory configured to access the UserAuth SQL Server DB
            var connStr = AppConfig.ConnectionString;

            container.Register<IDbConnectionFactory>(
                new OrmLiteConnectionFactory(connStr, //ConnectionString in Web.Config
                    SqlServerOrmLiteDialectProvider.Instance)
                    {
                        ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                    });

            //Store User Data into the referenced SqlServer database
            container.Register<IUserAuthRepository>(c => new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>())); //Use OrmLite DB Connection to persist the UserAuth and AuthProvider info

            var authRepo = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>(); //If using and RDBMS to persist UserAuth, we must create required tables
            if (appSettings.Get("RecreateAuthTables", false))
            {
                authRepo.DropAndReCreateTables(); //Drop and re-create all Auth and registration tables
            }
            else
            {
                authRepo.CreateMissingTables(); //Create only the missing tables
            }

            Plugins.Add(new RequestLogsFeature());
        }
 public void Compose(Container container)
 {
     container.RegisterAs<PersonRepository, IPersonRepository>();
 }
Exemplo n.º 11
0
        /**/
        public static void Start()
        {
            var store = new DocumentStore
                {
                    Url = "http://localhost:8080/",
                    DefaultDatabase = "svcStack"
                }
                .Initialize();

            new AppHost(store).Init();
        }

        public override void Configure(Container container)
        {
            var appSettings = new AppSettings();
            AppConfig = new AppConfig(appSettings);
            container.Register(AppConfig);

            container.Register<ICacheClient>(new MemoryCacheClient());

            //Set JSON web services to return idiomatic JSON camelCase properties
            JsConfig.EmitCamelCaseNames = true;
            Plugins.Add(new SwaggerFeature());

            //Configure User Defined REST Paths
            Routes
                .Add<Hello>("/hello")
                .Add<Hello>("/hello/{Name*}")
                //Custom services for this application
                .Add<Users>("/users/{UserIds}")
                .Add<UserProfile>("/profile");
            //Uncomment to change the default ServiceStack configuration
            //SetConfig(new EndpointHostConfig {
            //});

            //Enable Authentication
            ConfigureAuth(container);

            //Register all your dependencies
            container.Register(new TodoRepository());

            //Set MVC to use the same Funq IOC as ServiceStack
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
        }

        /* Uncomment to enable ServiceStack Authentication and CustomUserSession*/
        private void ConfigureAuth(Container container)
        {
            var appSettings = new AppSettings();

            //Default route: /auth/{provider}
            Plugins.Add(new AuthFeature(() => new CustomUserSession(),
                new IAuthProvider[] {
                    new CredentialsAuthProvider(appSettings),
                    //new FacebookAuthProvider(appSettings),
                    //new TwitterAuthProvider(appSettings),
                    //new BasicAuthProvider(appSettings),
                    new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Google OpenId
                    new YahooOpenIdOAuthProvider(appSettings), //Sign-in with Yahoo OpenId
                    new OpenIdOAuthProvider(appSettings),
                }));

            //Default route: /register
            Plugins.Add(new RegistrationFeature());

            //Requires ConnectionString configured in Web.Config
            container.RegisterAs<CustomRegistrationValidator, IValidator<Registration>>();

            container.Register<IUserAuthRepository>(c => new RavenUserAuthRepository(Store));
            CreateAdminIfNotPresent(container);
        }