views:

24

answers:

1

I am trying to create a custom resolver for automapper which needs to access one of my data repositories to retreive the logged in users account.

Here is my code so far...

public class FollowingResolver : ValueResolver<Audio, bool>
    {
        readonly IIdentityTasks identityTasks;

        public FollowingResolver(IIdentityTasks identitTasks)
        {
            this.identityTasks = identitTasks;
        }

        protected override bool ResolveCore(Audio source)
        {
            var user = identityTasks.GetCurrentIdentity();
            if (user != null)
                return user.IsFollowingUser(source.DJAccount);

            return false;
        }
    }

However I am getting this error:

FollowingResolver' does not have a default constructor

I have tried adding a default contrstructor but my repository never gets initialised then.

This is my autoampper initialisation code:

public static void Configure(IWindsorContainer container)
        {
            Mapper.Reset();
            Mapper.Initialize(x =>
            {
                x.AddProfile<AccountProfile>();
                x.AddProfile<AudioProfile>();
                x.ConstructServicesUsing(container.Resolve);
            });

            Mapper.AssertConfigurationIsValid();
        }

Am I missing something, is it even possible to do it like this or am I missing the boat here?

+1  A: 

Found the solution shorlty after...i was forgetting to add my resolvers as an IoC container.

Works great now!

Paul Hinett
you could as well use IoC.Resolve<ISomething>() anyware in your application
Omu