Skip to content

Conversation

@lbargaoanu
Copy link
Contributor

@lbargaoanu lbargaoanu commented Dec 9, 2016

Closes #1847.

@TylerCarlson1
Copy link
Contributor

This will break functionality in AutoMapper.Collections because it has the collection profile add 2 object mappers in specific locations in the mapper configuration list.

I understand this is technically better implementation in that the list resets on every mapper configuration created, but I'm curious is this a problem for people.

@lbargaoanu
Copy link
Contributor Author

See the issue. You just have to build the list yourself.

@TylerCarlson1
Copy link
Contributor

I don't think #1847 has anything to do with this. Could be wrong though.

@TylerCarlson1
Copy link
Contributor

Ok I see what you mean now. But alternatively can you make the mappers themselves thread safe as an alternative? That way there's no need to new up new classes every time?

@jbogard what do you think?

@lbargaoanu
Copy link
Contributor Author

There is no need to share them. They are created only when a new configuration is created.

@TylerCarlson1
Copy link
Contributor

Only thing I can think of is if you make ConvertMapper thread safe, you save on having to re-initialize Convert functions for unit tests, saving time generating expressions over and over again for each test.

@lbargaoanu
Copy link
Contributor Author

Actually they are lazy now.

@TylerCarlson1
Copy link
Contributor

They are lazy but if you are using a lot of converters in your mappings, you will have to lazy load them each test. You won't load all of them (hopefully), but if you do then for each test you will have to redo it each time.

How much time this will take and if this is a priority or not I don't know.

@lbargaoanu
Copy link
Contributor Author

I don't see a difference in our tests. And anyway, we're not going to optimize for that now :)

@lbargaoanu
Copy link
Contributor Author

@jbogard Can we merge this? I want to direct people to the MyGet build.

@jbogard
Copy link
Contributor

jbogard commented Dec 16, 2016

@lbargaoanu I left some questions, as this is a breaking change.

@lbargaoanu
Copy link
Contributor Author

Well, yes, but it's simple enough to pass the mappers. We can't keep a static property...

@lbargaoanu
Copy link
Contributor Author

Well, we could with ThreadStatic, but I suppose that's out of the question :)

@jbogard
Copy link
Contributor

jbogard commented Dec 16, 2016

In that case, if it's going to break, I'd rather just break it in a consistent way. This is a bit of a one-step-forwards-two-steps-back approach. I'll amend your PR...

@jbogard
Copy link
Contributor

jbogard commented Dec 19, 2016

I like it. @TylerCarlson1 the only downside still is that you can't access the mapper registry from a profile, that would be nice. But let's look at that in a follow-up PR. @lbargaoanu is this good to go?

@lbargaoanu
Copy link
Contributor Author

Yes.

{
private static readonly IObjectMapper[] _initialMappers =
public static IObjectMapper[] Mappers() => new IObjectMapper[]
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weird method. I wonder if we could just expose the property still, but make it very explicit of an IReadOnlyCollection? What would be the tradeoff?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a breaking change to the API. Is there a way to preserve the property but make this thread-safe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lbargaoanu sorry did you see these questions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, didn't see them :)
It doesn't help to make it ReadOnlyCollection, it's still a breaking change. The only way I can think of to keep it is through ThreadStatic. But that doesn't really make sense if it's exposed through config. It's breaking, but minor, few people use mappers I would say.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! I was trying out the Review feature in GitHub. Honestly don't understand the point of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither do I :)

@jbogard jbogard merged commit 094a2c1 into LuckyPennySoftware:master Dec 19, 2016
@jbogard jbogard changed the title Avoid static state Avoid static state; Mapper registry managed through mapper configuration Dec 19, 2016
@jbogard jbogard added this to the vNext milestone Dec 19, 2016
@lbargaoanu lbargaoanu deleted the RegistryMapper branch December 19, 2016 15:45
@lock
Copy link

lock bot commented May 6, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InvalidOperationException : ValueFactory attempted to access the Value property of this instance.

3 participants