IValidator could not be located with the ServiceLocator

240 views
Skip to first unread message

Markus Maga

unread,
Feb 28, 2011, 5:00:00 PM2/28/11
to sharp-arc...@googlegroups.com
I get the following exception when trying to use MyProject.ApplicationServices.SettingManagementService.SaveOrUpdate() method which was generated with scaffolding. 

Activation Exception:
The needed dependency of type IValidator could not be located with the ServiceLocator. You'll need to register it with the Common Service Locator (CSL) via your IoC's CSL adapter. Activation error occured while trying to get instance of type IValidator, key ""

When performing UnitTests I don't get any errors and the test passes but when I try to create a new using the website and when it tries to validate it, then it fails.

public ActionConfirmation SaveOrUpdate(Setting setting) {
            if (setting.IsValid()) {

Any thoughts? 

container.Register(
                    Component.For(typeof(IValidator))
                        .ImplementedBy(typeof(Validator))
                        .Named("validator"));

Is included in ComponentsRegistrar in AddComponentsTo()

Alec Whittington

unread,
Feb 28, 2011, 5:12:33 PM2/28/11
to sharp-arc...@googlegroups.com
Only time I've seen that is when it is not registered. Might want to debug to that piece of code to make sure it is in fact being registered in the container. I'm sure you've already done that, but thought I would mention it.

Alec

--
You received this message because you are subscribed to the Google Groups "S#arp Architecture" group.
To post to this group, send email to sharp-arc...@googlegroups.com.
To unsubscribe from this group, send email to sharp-architect...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sharp-architecture?hl=en.

Markus Maga

unread,
Feb 28, 2011, 6:36:17 PM2/28/11
to sharp-arc...@googlegroups.com
It does get added to the container just debugged it a few times and its the same type of Validator thats added to the container in the UnitTest as well, so no differences there either.

I also tried doing the same thing but with another object, controller, page, but end up with the same error.

If I remove the IsValid() check then the object gets saved to the database at least. Though that doesn't really seem like a good work around.

Thanks,
Markus

Seif Attar

unread,
Feb 28, 2011, 7:56:36 PM2/28/11
to sharp-arc...@googlegroups.com
Make sure you have a call to:
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
providing the container that you registered components with. (locator
initialization is usually in the global.asax.cs)
If that't there, make sure the IValidator that you are reigestering is
from the SharpArch.Core.CommonValidator not
NHibernate.Validator.Engine

Other than what Alec mentiond, I can't think of another reason why
this could be happening. maybe someone else has some ideas.

Markus Maga

unread,
Feb 28, 2011, 8:33:12 PM2/28/11
to sharp-arc...@googlegroups.com
Ah! Solved it.

It was registering the NHibernate one instead of the SharpArch validator.

Thanks for the help,
Markus

cjjohansen

unread,
Apr 14, 2011, 6:37:07 AM4/14/11
to S#arp Architecture
Hi

I Got the same error when trying to save my single simple domain
object using the v. 1.9.6 version of SharpArchitecture and replaced

using NHibernate.Validator.Engine;


with

using SharpArch.Core.CommonValidator;


in ComponentRegistrar.cs

It now works,

But why does the valiator in NHibernate.Validator.Engine not work ?

The project template ought to be updated.

BR Christian

Alec Whittington

unread,
Apr 14, 2011, 11:17:21 AM4/14/11
to sharp-arc...@googlegroups.com
Feel free to join in an update it. This is an OPEN SOURCE project, we do accept community submissions.

Reply all
Reply to author
Forward
0 new messages