Example #1
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();
 }
        public static void Register()
        {
            // Get IoC container
            var container = new TinyIoC.TinyIoCContainer();

            // Register context, unit of work and repos with per request lifetime
            container.Register<IMusicInstrumentRepository, EFMusicInstrumentsRepository>().AsPerRequestSingleton();

            // Set MVC dep resolver
            System.Web.Mvc.DependencyResolver.SetResolver(new TinyIoCMvcResolver(container));
        }
Example #3
0
        //protected override byte[] DefaultFavIcon
        //{
        //    get
        //    {
        //        if (favicon == null)
        //        {
        //            using (MemoryStream ms = new MemoryStream())
        //            {
        //                Resource1.favicon.Save(ms);
        //                favicon = ms.ToArray();
        //            }
        //        }
        //        return favicon;
        //    }
        //}

        protected override void ApplicationStartup(TinyIoC.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            DataAnnotationsValidator.RegisterAdapter(typeof(MatchAttribute), (v, d) => new CustomDataAdapter((MatchAttribute)v));

            Func <TinyIoCContainer, NamedParameterOverloads, IDocumentSession> factory = (ioccontainer, namedparams) => { return(new RavenSessionProvider().GetSession()); };

            container.Register <IDocumentSession>(factory);



            Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(IndexEventDate).Assembly, RavenSessionProvider.DocumentStore);
            Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(IndexUserLogin).Assembly, RavenSessionProvider.DocumentStore);
            Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(IndexMostPopularDinners).Assembly, RavenSessionProvider.DocumentStore);
            Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(IndexMyDinners).Assembly, RavenSessionProvider.DocumentStore);

            pipelines.OnError += (context, exception) =>
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
                return(null);
            };
        }
Example #4
0
        protected override void ConfigureRequestContainer(TinyIoC.TinyIoCContainer container, NancyContext context)
        {
            base.ConfigureRequestContainer(container, context);

            container.Register <IUserMapper, UserMapper>();
        }
Example #5
0
 public static void RegisterSingleton <TInterface, T>() where TInterface : class where T : class, TInterface
 {
     _container.Register <TInterface, T>().AsSingleton();
 }