jgauffin / griffin.mvccontrib

A contribution project for ASP.NET MVC3
http://blog.gauffin.org/tag/griffin-mvccontrib/
GNU Lesser General Public License v3.0
83 stars 40 forks source link

Remove DependencyResolver #21

Closed tdekoekkoek closed 12 years ago

tdekoekkoek commented 12 years ago

I don't think you should be using DependencyResolver as that is specific to Web.Mvc. Your membership provider should be independent of Mvc. Also the error you give is misleading as it's not actually a service locator that is missing, but rather dependency resolver:

        get
        {
            if (_userService == null)
            {
                _userService = DependencyResolver.Current.GetService<IAccountRepository>();
                if (_userService == null)
                    throw new InvalidOperationException(
                        "You need to assign a locator to the ServiceLocator property and it should be able to lookup IAccountRepository.");
            }
            return _userService;

I'm having a beast of a time unit testing this as the dependencyresolover is always failing for some reason, even if I initialize it in my test setup fixture. I think if you would just assign the service locator, it would be sufficient:

        UnityServiceLocator locator = new UnityServiceLocator(_container);
        ServiceLocator.SetLocatorProvider(() => locator);
jgauffin commented 12 years ago

It's a MvcContrib project ;)

tdekoekkoek commented 12 years ago

Good point. Well maybe the error message could be changed, because it's the dependency resolver that should be set. But my main issue is I wasn't able to get this to work in my unit tests. I kept getting this error even when I set my dependency resolver in the setup. Any ideas?

jgauffin commented 11 years ago

Show me the code for the unit test.

On Mon, Aug 20, 2012 at 12:48 PM, Trevor de Koekkoek < notifications@github.com> wrote:

Good point. Well maybe the error message could be changed, because it's the dependency resolver that should be set. But my main issue is I wasn't able to get this to work in my unit tests. I kept getting this error even when I set my dependency resolver in the setup. Any ideas?

— Reply to this email directly or view it on GitHubhttps://github.com/jgauffin/griffin.mvccontrib/issues/21#issuecomment-7865862.