protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
        {
            base.ConfigureApplicationContainer(container);

            container.Register<Repositories.IAppUserMapper, Repositories.InMemoryAppUserMapper>().AsSingleton();
            container.Register<IUserMapper>(container.Resolve<Repositories.IAppUserMapper>());
        }
 protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
 {
     base.ApplicationStartup(container, pipelines);
     pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(
         container.Resolve<IUserValidator>(),
         "NancyFx"));
 }
Esempio n. 3
0
 protected override void RegisterViewEngines(TinyIoC.TinyIoCContainer container, IEnumerable<Type> viewEngineTypes)
 {
     if (viewEngineTypes.Count() > 1) //No need to register it because the default Container has already done it.
     {
         this.container.RegisterMultiple<IViewEngine>(viewEngineTypes).AsSingleton();
     }
 }
 private void RegisterIFacebookApplicationPerRequest(TinyIoC.TinyIoCContainer container, NancyContext context)
 {
     Facebook.IFacebookApplication facebookApplication = null;
     if (context != null && context.Request != null && context.Request.Url != null)
     {
         var url = context.Request.Url;
         if (url.HostName == "localhost")
         {
             facebookApplication = new Facebook.DefaultFacebookApplication
                                       {
                                           AppId = ",
                                           AppSecret = ",
                                           SiteUrl = "http://localhost:45254/",
                                           CanvasUrl = "http://localhost:45254/canvas/",
                                           SecureCanvasUrl = "https://localhost:44302/canvas/",
                                           CanvasPage = "http://apps.facebook.com/appname/
                                       };
         }
         else
         {
             //facebookApplication = new Facebook.DefaultFacebookApplication { AppId = "", AppSecret = "" };
         }
     }
     container.Register(facebookApplication);
     }
 protected override void ConfigureRequestContainer(TinyIoC.TinyIoCContainer container)
 {
     foreach (var mock in _mocks)
     {
         container.Register(mock.Key, mock.Value);
     }
 }
Esempio n. 6
0
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            // In reality you would use a pre-built authentication/claims provider
            this.BeforeRequest += (ctx) =>
            {
                // World's-worse-authentication (TM)
                // Pull the username out of the querystring if it exists
                // and build claims from it
                var username = ctx.Request.Query.username;

                if (username.HasValue)
                {
                    ctx.Items[Nancy.Security.SecurityConventions.AuthenticatedUsernameKey] = username.ToString();
                    ctx.Items[Nancy.Security.SecurityConventions.AuthenticatedClaimsKey] = BuildClaims(username.ToString());
                }

                return null;
            };

            this.AfterRequest += (ctx) =>
            {
                // If status code comes back as Unauthorized then
                // forward the user to the login page
                if (ctx.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    ctx.Response = new RedirectResponse("/login?returnUrl=" + Uri.EscapeDataString(ctx.Request.Path));
                }
            };
        }
        protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
        {
            base.ConfigureApplicationContainer(container);

              container.Register<IRaceData>(new RaceData(_args.AlwaysUseCache));
              container.Register<IOutput, CliOutput>();
        }
        protected override void RequestStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines, NancyContext context)
        {
            base.RequestStartup(container, pipelines, context);

            pipelines.BeforeRequest.AddItemToStartOfPipeline(
                ctx =>
                {
                    var facebookClient = container.Resolve<Facebook.FacebookClient>();
                    var fbUser = context.CurrentUser as IFacebookUser;
                    if (fbUser != null)
                        facebookClient.AccessToken = fbUser.FacebookAccessToken;

                    #region SignedRequest

                    if (context.Request != null)
                    {
                        dynamic signedRequest;
                        var fbApp = container.Resolve<Facebook.IFacebookApplication>();
                        if (context.Request.TryParseFacebookSignedRequest(fbApp.AppId, fbApp.AppSecret, out signedRequest))
                        {
                            if (signedRequest.ContainsKey("oauth_token"))
                                facebookClient.AccessToken = signedRequest.oauth_token;
                        }
                    }

                    #endregion

                    return null;
                });
        }
Esempio n. 9
0
        protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
        {
            base.ConfigureApplicationContainer(container);

              var mongoUrlStore = new MongoUrlStore("mongodb://localhost:27010/short_url");
              container.Register<UrlStore>(mongoUrlStore);
        }
        public static void ProcessRegistrations(TinyIoC.TinyIoCContainer container)
        {
            var applicationRegistrationImplementations =
                AppDomain.CurrentDomain.GetAssemblies()
                    .Where(a =>
                           a.GetReferencedAssemblies().Contains(typeof (ApplicationRegistar).Assembly.GetName()) ||
                           a == typeof (ApplicationRegistar).Assembly)
                    .SelectMany(t => t.GetTypes())
                    .Where(t => t.Implements(typeof (IApplicationRegistration)))
                    .ToList();

            container.RegisterMultiple<IApplicationRegistration>(applicationRegistrationImplementations);

            var applicationRegistrations = container.ResolveAll<IApplicationRegistration>().ToList();

            foreach (var typeRegistration in applicationRegistrations.SelectMany(ar => ar.TypeRegistrations))
            {
                container.Register(typeRegistration.RegistrationType, typeRegistration.InstanceType);
            }

            foreach (var instanceRegistration in applicationRegistrations.SelectMany(ar => ar.InstanceRegistrations))
            {
                container.Register(instanceRegistration.RegistrationType, instanceRegistration.Instance);
            }

            foreach (var collectionRegistration in applicationRegistrations.SelectMany(ar => ar.CollectionRegistration).GroupBy(cr => cr.RegistrationType))
            {
                container.RegisterMultiple(collectionRegistration.Key, collectionRegistration.SelectMany(c => c.InstanceTypes));
            }
        }
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            BeforeRequest += ctx =>
            {
                var staticFileExtensions =
                    new Dictionary<string, string>
                        {
                            { "jpg", "image/jpg" },
                            { "png", "image/png" },
                            { "css", "text/css" },
                            { "js",  "text/javascript" }
                        };

                var requestedExtension =
                    Path.GetExtension(ctx.Request.Uri);

                if (!string.IsNullOrEmpty(requestedExtension))
                {
                    var extensionWithoutDot =
                        requestedExtension.Substring(1);

                    if (staticFileExtensions.Keys.Any(x => x.Equals(extensionWithoutDot, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        var filePath = "Public" + ctx.Request.Uri.Replace('/', '\\');

                        return new GenericFileResponse(filePath, staticFileExtensions[extensionWithoutDot]);
                    }
                }

                return null;
            };
        }
 protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
 {
     FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration {
         RedirectUrl = "~/login",
         UserMapper = _mocks[typeof(IUserRepository)] as IUserRepository
     });
 }
Esempio n. 13
0
 // Overriding this just to show how it works, not actually necessary as autoregister
 // takes care of it all.
 protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer existingContainer)
 {
     // We don't call base because we don't want autoregister
     // we just register our one known dependency as an application level singleton
     existingContainer.Register<IApplicationDependency, ApplicationDependencyClass>().AsSingleton();
     existingContainer.Register<IRazorConfiguration, MyRazorConfiguration>().AsSingleton();
 }
Esempio n. 14
0
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            var configuration = new StitchConfiguration()
                                    {
                                        /*Compilers = new[]
                                                        {
                                                            new StitchConfigurationCompiler {Type = typeof (JavaScriptCompiler).AssemblyQualifiedName, Extension = ".js"},
                                                            new StitchConfigurationCompiler {Type = typeof (CoffeeScriptCompiler).AssemblyQualifiedName, Extension = ".coffee"},
                                                            new StitchConfigurationCompiler {Type = typeof (jQueryTemplateCompiler).AssemblyQualifiedName, Extension = ".tmpl"}
                                                        },*/
                                        Files = new[]
                                                    {
                                                        new StitchConfiguration()
                                                            {
                                                                Name = "/Scripts/app.stitch",
                                                                Paths = new[]
                                                                            {
                                                                                "Scripts/App"
                                                                            }
                                                            }
                                                    }
                                    };

            container.Register<IStitchConfiguration>(configuration);

            Stitch.Enable(this, container.Resolve<IRootPathProvider>(), container.Resolve<IStitchConfiguration>());
        }
Esempio n. 15
0
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            this.BeforeRequest += (ctx) =>
            {
                // World's-worse-authentication (TM)
                // Pull the username out of the querystring if it exists
                // and build claims from it
                var username = ctx.Request.Query.username;

                if (username.HasValue)
                {
                    ctx.Items[Security.USERNAME_KEY] = username.ToString();
                    ctx.Items[Security.CLAIMS_KEY] = BuildClaims(username.ToString());
                }

                return null;
            };

            this.AfterRequest += (ctx) =>
            {
                // If status code comes back as Unauthorized then
                // forward the user to the login page
                if (ctx.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    ctx.Response = new RedirectResponse("/login?returnUrl=" + ctx.Request.Uri);
                }
            };
        }
Esempio n. 16
0
 protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
 {
     container.Register(documentStore);
       container.Register(s3Configuration);
       container.Register<IS3Storage, RavenDBStorage>().AsSingleton();
       container.Register<IS3Responder, S3XmlResponder>().AsSingleton();
 }
        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            // In reality you would use a pre-built authentication/claims provider
            pipelines.BeforeRequest += (ctx) =>
            {
                // World's-worse-authentication (TM)
                // Pull the username out of the querystring if it exists
                // and build claims from it
                var username = ctx.Request.Query.username;

                if (username.HasValue)
                {
                    ctx.CurrentUser = new DemoUserIdentity
                                          {
                                              UserName = username.ToString(),
                                              Claims = BuildClaims(username.ToString())
                                          };
                }

                return null;
            };

            pipelines.AfterRequest += (ctx) =>
            {
                // If status code comes back as Unauthorized then
                // forward the user to the login page
                if (ctx.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    ctx.Response = new RedirectResponse("/login?returnUrl=" + Uri.EscapeDataString(ctx.Request.Path));
                }
            };
        }
        private Response FacebookRequestStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines, NancyContext context)
        {
            if (context.Request != null)
            {
                string[] perms = null;
                dynamic signedRequest;
                var fbApp = container.Resolve<IFacebookApplication>();
                if (context.TryParseFacebookSignedRequest(fbApp.AppId, fbApp.AppSecret, out signedRequest))
                {
                    if (((System.Collections.Generic.IDictionary<string, object>)signedRequest).ContainsKey("oauth_token"))
                    {
                        var fb = container.Resolve<FacebookClient>();
                        fb.AccessToken = signedRequest.oauth_token;
                        try
                        {
                            var result = (IDictionary<string, object>)fb.Get("me/permissions");
                            perms = ((IDictionary<string, object>)((IList<object>)result["data"])[0]).Keys.ToArray();
                        }
                        catch (FacebookOAuthException)
                        {
                            // access token is invalid so perms=none
                            // but don't throw exception.
                            fb.AccessToken = null;  
                        }
                    }
                }

                context.Items[CustomFacebookExtensions.FacebookPermsKey] = perms ?? new string[0];
            }

            return null;
        }
Esempio n. 19
0
        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            StaticConfiguration.DisableErrorTraces = false;

            SassAndCoffee.Hooks.Enable(pipelines, new InMemoryCache(), container.Resolve<IRootPathProvider>());
        }
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            this.EnableBasicAuthentication(new BasicAuthenticationConfiguration(
                container.Resolve<IUserValidator>(),
                "MyRealm"));
        }
Esempio n. 21
0
        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);
            CookieBasedSessions.Enable(pipelines);

            Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(AllDocsByTypeIndex).Assembly,
                                                                RavenSessionProvider.DocumentStore);
        }
Esempio n. 22
0
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);

            this.BeforeRequest += CheckCache;

            this.AfterRequest += SetCache;
        }
Esempio n. 23
0
 protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
 {
     base.ConfigureApplicationContainer(container);
     container.Register(typeof(NameValueCollection), ConfigurationManager.AppSettings);
     DocumentStoreContainer.Initialize();
     container.Register(DocumentStoreContainer.Instance);
     container.Register((ioc, _) => ioc.Resolve<IDocumentStore>().OpenSession());
 }
Esempio n. 24
0
        /// <summary>
        /// Configures dependencies into the dependency container
        /// </summary>
        /// <param name="container"></param>
        internal static void Configure(TinyIoC.TinyIoCContainer container) {
            container.Register<IMessageTypeResolver, DefaultMessageTypeResolver>();

            container.Register<MessageEventDispatcher>().AsSingleton();

            container.Register<IMessageSerializerFactory, JsonMessageSerializerFactory>();
            container.Register<IMessageDeserializerFactory, JsonMessageDeserializerFactory>();
        }
Esempio n. 25
0
 protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
 {
     #if (DEBUG)
     base.ApplicationStartup (container, pipelines);
     StaticConfiguration.DisableErrorTraces = false;
     StaticConfiguration.DisableCaches = true;
     #endif
 }
Esempio n. 26
0
        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            pipelines.BeforeRequest += CheckCache;

            pipelines.AfterRequest += SetCache;
        }
        protected override void ConfigureRequestContainer(TinyIoC.TinyIoCContainer container, NancyContext context)
        {
            base.ConfigureRequestContainer(container, context);

            RegisterFacebookClientPerRequest(container, context);
            RegisterIFacebookApplicationPerRequest(container, context);
            RegisterFacebookOAuthClientPerRequest(container, context);
        }
Esempio n. 28
0
        protected override void InitialiseInternal(TinyIoC.TinyIoCContainer container)
        {
            base.InitialiseInternal(container);
            var formsAuthConfiguration =
                new FormsAuthenticationConfiguration()
                {
                    Passphrase = "SuperSecretPass",
                    Salt = "AndVinegarCrisps",
                    HmacPassphrase = "UberSuperSecure",
                    RedirectUrl = "/authentication/login",
                    UsernameMapper = container.Resolve<IUsernameMapper>(),
                };

            FormsAuthentication.Enable(this, formsAuthConfiguration);

            BeforeRequest += ctx =>
            {
                var rootPathProvider =
                    container.Resolve<IRootPathProvider>();

                var staticFileExtensions =
                    new Dictionary<string, string>
                    {
                        { "jpg", "image/jpg" },
                        { "png", "image/png" },
                        { "gif", "image/gif" },
                        { "css", "text/css" },
                        { "js",  "text/javascript" }
                    };

                var requestedExtension =
                    Path.GetExtension(ctx.Request.Uri);

                if (!string.IsNullOrEmpty(requestedExtension))
                {
                    var extensionWithoutDot =
                        requestedExtension.Substring(1);

                    if (staticFileExtensions.Keys.Any(x => x.Equals(extensionWithoutDot, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        var fileName =
                            Path.GetFileName(ctx.Request.Uri);

                        if (fileName == null)
                        {
                            return null;
                        }

                        var filePath =
                            Path.Combine(rootPathProvider.GetRootPath(), "content", fileName);

                        return !File.Exists(filePath) ? null : new StaticFileResponse(filePath, staticFileExtensions[extensionWithoutDot]);
                    }
                }

                return null;
            };
        }
        public override void ConfigureRequestContainer(TinyIoC.TinyIoCContainer container)
        {
            base.ConfigureRequestContainer(container);

            RequestContainerConfigured = true;

            container.Register<IFoo, Foo>().AsSingleton();
            container.Register<IDependency, Dependency>().AsSingleton();
        }
Esempio n. 30
0
        protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container)
        {
            var mefcontainer = CreateCompositionContainer();

            container.Register(mefcontainer.GetExportedValues<IAnnounce>());
            container.Register(mefcontainer.GetExportedValues<ISprocketInitializer>());
            container.Register(new SprocketManager(mefcontainer.GetExportedValues<ISprocket>()));
            container.Register(new Bot(_serverUrl, _botName, _botPassword));
        }