Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to map an object to an interface #237

Open
DevilKall opened this issue Feb 29, 2024 · 0 comments
Open

How to map an object to an interface #237

DevilKall opened this issue Feb 29, 2024 · 0 comments

Comments

@DevilKall
Copy link

Sorry, I cannot find any documentation about this apparently easy task.
The situation is this:

    public interface IFoo
    {
        string Name { get; set; }
    }

    public class FooDto : IFoo
    {
        public string Name { get; set; }
    }

    public class Foo
    {
        public string Name { get; set; }
    }

I'm tring to configure the following mappings:

public class FooMappingConfiguration : MapperConfiguration
{
    protected override void Configure()
    {
        GetPlansFor<Foo>().To<FooDto>();  // works
        GetPlansFor<IFoo>().To<Foo>();  // works

        WhenMapping
            .From<Foo>().To<IFoo>()                
            .MapTo<FooDto>()
            ;

        GetPlansFor<Foo>().To<IFoo>();  // doesn't work!!!
    }
}

When I test the mapping plans it gives me the following error:

 MappingPlansComplete
 Duration: 789 ms

Message: 
Test method Example.Tests.AgileMapperTests.FooMapping_Test.MappingPlansComplete threw exception:
AgileObjects.AgileMapper.Validation.MappingValidationException: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Foo -> IFoo
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 Rule set: CreateNew

 Unmappable target Types - fix by ignoring or configuring constructor parameters or factory methods:

  - Foo -> IFoo

Stack Trace: 
MappingValidator.VerifyMappingPlanIsComplete(IEnumerable`1 mapperDatas)
MappingValidator.Validate(Mapper mapper)
IMapper.ThrowNowIfAnyMappingPlanIsIncomplete()
FooMapping_Test.MappingPlansComplete() line 29

I also tried with CreateInstancesOf but the error remains the same.
What am I doing wrong? Any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant