-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ServiceLocator in QueryFactory - how to use
PostPosted: Mon Mar 28, 2011 1:27 pm 
Newbie

Joined: Mon Mar 28, 2011 1:14 pm
Posts: 2
How do I use IServiceLocator within a repository QueryFactory?

I am using an example from NHibernate 3.0 Cookbook which includes the following QueryFactory class. I have never used a service locator before and was wondering how I should be configuring it for use.
Code:
    public class QueryFactory : IQueryFactory
    {
        private readonly IServiceLocator _serviceLocator;

        public QueryFactory(IServiceLocator serviceLocator)
        {
            _serviceLocator = serviceLocator;
        }

        public TQuery CreateQuery<TQuery>() where TQuery : IQuery
        {
            return _serviceLocator.GetInstance<TQuery>();
        }
    }


The QueryFactory is created in the repository constructor using
Code:
IServiceLocator serviceLocator = ServiceLocator.Current;

            IQueryFactory queryFactory = new QueryFactory(serviceLocator);

however, ServiceLocator.Current throws a Null exception when I create the repository.

Can someone please point me in right direction.
Thanks,


Top
 Profile  
 
 Post subject: Re: ServiceLocator in QueryFactory - how to use
PostPosted: Tue Mar 29, 2011 10:53 am 
Newbie

Joined: Mon Mar 28, 2011 1:14 pm
Posts: 2
The source code that goes with the NHibernate 3.0 cookbook has examples that explain how to do this.

Code:
      var kernel = new StandardKernel();

      kernel.Bind<ISessionFactory>().ToConstant(SessionFactory);
      kernel.Bind<IQueryFactory>().To<QueryFactoryImpl>();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.