示例#1
0
        private static ISessionFactory BuildTestSessionFactory()
        {
            var testDatabaseConnectionString = "LocalDB";
            var config = DatabaseConfiguration.Configure(testDatabaseConnectionString);

            /*
             * Need to comment these out when not needed because session factory can only be created once.
             * Database schemas need to be created BEFORE NHibernate schema export.
             * This needs to be run only once.
             */
            /*
             * var fac = DatabaseConfiguration.BuildSessionFactory(config);
             *
             * CreateSchemas(fac);*/

            // Drop old database if any, create new schema
            config.ExposeConfiguration(cfg => {
                var export = new SchemaExport(cfg);
                //export.SetOutputFile(@"C:\Temp\vdb.sql");
                export.Drop(false, true);
                export.Create(false, true);
            });

            var fac = DatabaseConfiguration.BuildSessionFactory(config);

            FinishDatabaseConfig(fac);

            return(fac);
        }
示例#2
0
        public ISessionFactory BuildTestSessionFactory()
        {
            var testDatabaseConnectionString = "LocalDB";
            var config = DatabaseConfiguration.Configure(testDatabaseConnectionString);

            // Database schemas need to be created BEFORE NHibernate schema export.
            CreateSchemas(testDatabaseConnectionString);

            config.ExposeConfiguration(cfg => RecreateSchema(cfg, testDatabaseConnectionString));

            var fac = DatabaseConfiguration.BuildSessionFactory(config);

            return(fac);
        }
示例#3
0
        public static void RegisterComponent()
        {
            var builder = new ContainerBuilder();

            // Register services.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterType <QueryService>();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModule(new AutofacWebTypesModule());

            builder.Register(x => DatabaseConfiguration.BuildSessionFactory()).SingleInstance();

            // Other dependencies (for repositories mostly)
            builder.RegisterType <LoginManager>().As <IUserPermissionContext>();
            builder.Register(x => new EntryAnchorFactory(AppConfig.HostAddress)).As <IEntryLinkFactory>();
            builder.RegisterType <UserMessageMailer>().As <IUserMessageMailer>();
            builder.RegisterType <StopForumSpamClient>().As <IStopForumSpamClient>();
            builder.RegisterType <PVParser>().As <IPVParser>();
            builder.RegisterType <ServerEntryImagePersisterOld>().As <IEntryImagePersisterOld>().As <IEntryPictureFilePersister>();
            builder.RegisterType <ServerEntryThumbPersister>().As <IEntryThumbPersister>();
            builder.RegisterType <NTextCatLibLanguageDetector>().As <ILanguageDetector>();
            builder.RegisterType <BrandableStringsManager>().AsSelf().SingleInstance();
            builder.RegisterType <VdbConfigManager>().AsSelf().SingleInstance();
            builder.RegisterType <GravatarUserIconFactory>().As <IUserIconFactory>();
            builder.RegisterType <EntryUrlParser>().As <IEntryUrlParser>().SingleInstance();
            builder.RegisterType <AlbumDescriptionGenerator>().AsSelf().SingleInstance();
            builder.RegisterType <MarkdownParser>().AsSelf();
            builder.Register(x => new IPRuleManager(LoadBlockedIPs(x))).AsSelf().SingleInstance();
            builder.Register(_ => MemoryCache.Default).As <ObjectCache>().ExternallyOwned();            // Disable dispose
            builder.RegisterType <EntryForApiContractFactory>().AsSelf();
            builder.RegisterType <EnumTranslations>().As <IEnumTranslations>();

            // Legacy services
            builder.RegisterType <ActivityFeedService>().AsSelf();
            builder.RegisterType <AdminService>().AsSelf();
            builder.RegisterType <AlbumService>().AsSelf();
            builder.RegisterType <ArtistService>().AsSelf();
            builder.RegisterType <MikuDbAlbumService>().AsSelf();
            builder.RegisterType <OtherService>().AsSelf();
            builder.RegisterType <ReleaseEventService>().AsSelf();
            builder.RegisterType <SongService>().AsSelf();
            builder.RegisterType <UserService>().AsSelf();

            // Repositories
            builder.RegisterType <NHibernateRepository>().As <IRepository>();
            builder.RegisterType <AlbumNHibernateRepository>().As <IAlbumRepository>();
            builder.RegisterType <ArtistNHibernateRepository>().As <IArtistRepository>();
            builder.RegisterType <DiscussionFolderNHibernateRepository>().As <IDiscussionFolderRepository>();
            builder.RegisterType <EntryReportNHibernateRepository>().As <IEntryReportRepository>();
            builder.RegisterType <EventNHibernateRepository>().As <IEventRepository>();
            builder.RegisterType <SongNHibernateRepository>().As <ISongRepository>();
            builder.RegisterType <SongListNHibernateRepository>().As <ISongListRepository>();
            builder.RegisterType <TagNHibernateRepository>().As <ITagRepository>();
            builder.RegisterType <UserNHibernateRepository>().As <IUserRepository>();
            builder.RegisterType <UserMessageNHibernateRepository>().As <IUserMessageRepository>();
            builder.RegisterType <AlbumQueries>().AsSelf();
            builder.RegisterType <ArtistQueries>().AsSelf();
            builder.RegisterType <DiscussionQueries>().AsSelf();
            builder.RegisterType <EntryQueries>().AsSelf();
            builder.RegisterType <EntryReportQueries>().AsSelf();
            builder.RegisterType <EventQueries>().AsSelf();
            builder.RegisterType <SongQueries>().AsSelf();
            builder.RegisterType <SongAggregateQueries>().AsSelf();
            builder.RegisterType <SongListQueries>().AsSelf();
            builder.RegisterType <TagQueries>().AsSelf();
            builder.RegisterType <UserQueries>().AsSelf();
            builder.RegisterType <UserMessageQueries>().AsSelf();

            // Enable DI for action filters
            builder.Register(c => new RestrictBlockedIPAttribute(c.Resolve <IPRuleManager>()))
            .AsActionFilterFor <Controller>().InstancePerRequest();

            builder.RegisterFilterProvider();

            // Build container.
            var container = builder.Build();

            // Set ASP.NET MVC dependency resolver.
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));                              // For ASP.NET MVC
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container); // For Web API
            AutofacHostFactory.Container = container;                                                              // For WCF
        }
示例#4
0
        public static void RegisterComponent()
        {
            var builder = new ContainerBuilder();

            // Register services.
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterType <QueryService>();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModule(new AutofacWebTypesModule());

            builder.Register(x => DatabaseConfiguration.BuildSessionFactory()).SingleInstance();

            // Other dependencies (for repositories mostly)
            builder.RegisterType <LoginManager>().As <IUserPermissionContext>();
            builder.Register(x => new EntryAnchorFactory(AppConfig.HostAddress)).As <IEntryLinkFactory>();
            builder.RegisterType <UserMessageMailer>().As <IUserMessageMailer>();
            builder.RegisterType <StopForumSpamClient>().As <IStopForumSpamClient>();
            builder.RegisterType <PVParser>().As <IPVParser>();
            builder.RegisterType <ServerEntryImagePersisterOld>().As <IEntryImagePersisterOld>();
            builder.RegisterType <ServerEntryThumbPersister>().As <IEntryThumbPersister>();
            builder.RegisterType <NTextCatLibLanguageDetector>().As <ILanguageDetector>();
            builder.RegisterType <BrandableStringsManager>().AsSelf().SingleInstance();
            builder.RegisterType <VdbConfigManager>().AsSelf().SingleInstance();
            builder.RegisterType <GravatarUserIconFactory>().As <IUserIconFactory>();
            builder.Register(_ => MemoryCache.Default).As <ObjectCache>();

            // Legacy services
            builder.RegisterType <ServiceModel>().AsSelf();
            builder.RegisterType <ActivityFeedService>().AsSelf();
            builder.RegisterType <AdminService>().AsSelf();
            builder.RegisterType <AlbumService>().AsSelf();
            builder.RegisterType <ArtistService>().AsSelf();
            builder.RegisterType <MikuDbAlbumService>().AsSelf();
            builder.RegisterType <OtherService>().AsSelf();
            builder.RegisterType <RankingService>().AsSelf();
            builder.RegisterType <ReleaseEventService>().AsSelf();
            builder.RegisterType <SongService>().AsSelf();
            builder.RegisterType <TagService>().AsSelf();
            builder.RegisterType <UserService>().AsSelf();

            // Repositories
            builder.RegisterType <AlbumNHibernateRepository>().As <IAlbumRepository>();
            builder.RegisterType <ArtistNHibernateRepository>().As <IArtistRepository>();
            builder.RegisterType <EntryReportNHibernateRepository>().As <IEntryReportRepository>();
            builder.RegisterType <EventNHibernateRepository>().As <IEventRepository>();
            builder.RegisterType <SongNHibernateRepository>().As <ISongRepository>();
            builder.RegisterType <SongListNHibernateRepository>().As <ISongListRepository>();
            builder.RegisterType <TagNHibernateRepository>().As <ITagRepository>();
            builder.RegisterType <UserNHibernateRepository>().As <IUserRepository>();
            builder.RegisterType <UserMessageNHibernateRepository>().As <IUserMessageRepository>();
            builder.RegisterType <AlbumQueries>().AsSelf();
            builder.RegisterType <ArtistQueries>().AsSelf();
            builder.RegisterType <EntryQueries>().AsSelf();
            builder.RegisterType <EntryReportQueries>().AsSelf();
            builder.RegisterType <EventQueries>().AsSelf();
            builder.RegisterType <SongQueries>().AsSelf();
            builder.RegisterType <SongListQueries>().AsSelf();
            builder.RegisterType <TagQueries>().AsSelf();
            builder.RegisterType <UserQueries>().AsSelf();
            builder.RegisterType <UserMessageQueries>().AsSelf();

            // Build container.
            var container = builder.Build();

            // Set ASP.NET MVC dependency resolver.
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));                              // For ASP.NET MVC
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container); // For Web API
            AutofacHostFactory.Container = container;                                                              // For WCF
        }