コード例 #1
0
        public IServiceLocator GetServiceLocator()
        {
            var sl = new HomeMadeServiceLocator();

            var nhConfigurator = new DefaultSessionFactoryConfigurationProvider();

            nhConfigurator.AfterConfigure += ((sender, e) => new SchemaExport(e.Configuration).Create(false, true));
            var sfp = new SessionFactoryProvider(nhConfigurator);

            sl.LoadSingletonService <ISessionFactoryProvider>(sfp);

            sl.LoadSingletonService <IConversationFactory>(new DefaultConversationFactory(sfp, new FakeSessionWrapper()));

            sl.LoadSingletonService <IConversationsContainerAccessor>(new NhConversationsContainerAccessor(sfp));

            sl.LoadSingletonService <IDaoFactory>(new DaoFactory(sl));
            sl.LoadDelegatedService(() => sfp.GetFactory(null));
            LoadNaturalnessDaos <Reptile>(sl);
            LoadNaturalnessDaos <Human>(sl);
            LoadNaturalnessModels <Reptile>(sl);
            LoadNaturalnessModels <Human>(sl);
            return(sl);
        }
コード例 #2
0
        private static void LoadNaturalnessDaos <T>(HomeMadeServiceLocator sl) where T : Animal
        {
            var animalDao = new AnimalDao <T>(sl.Resolve <ISessionFactory>());

            sl.LoadSingletonService <IAnimalReadOnlyDao <T> >(animalDao);
            sl.LoadSingletonService <ICrudDao <T> >(animalDao);
            sl.LoadSingletonService <IDao <T> >(animalDao);

            var familyDao = new FamilyDao <T>(sl.Resolve <ISessionFactory>());

            sl.LoadSingletonService <IFamilyDao <T> >(familyDao);
            sl.LoadSingletonService <ICrudDao <Family <T> > >(familyDao);
            sl.LoadSingletonService <IDao <Family <T> > >(familyDao);
        }