NCommon without ServiceLocator

32 views
Skip to first unread message

Александр Пав

unread,
Jun 25, 2013, 1:11:20 PM6/25/13
to nco...@googlegroups.com
Hey!
We try to use NCommon for our project but we have a several composition root. Therefore we can't to define a global ServiceLocator. I 've found that It's possible to override UnitOfWorkScope, TransactionManager and LinqToSqlRepository to replace ServiceLocator.Current on IUnityContainer. But LinqToSqlRepository have a bad dependency in constructor, although there is a check ServiceLocator.Current !=null but It'll have risk that somebody set one. Can u enter virtual method in LinqToSqlRepository for this code:
            if (ServiceLocator.Current == null)
                return;

            var sessions = ServiceLocator.Current.GetAllInstances<ILinqToSqlSession>();
            if (sessions != null && sessions.Count() > 0)
                _privateSession = sessions.FirstOrDefault();

Ritesh Rao

unread,
Jun 25, 2013, 1:48:47 PM6/25/13
to nco...@googlegroups.com
Feel free to fork the source in Git to virtualize the method and send me a pull request.

Thanks,
Ritesh.
Reply all
Reply to author
Forward
0 new messages