question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecating Resolve(Type, IDictionary) in favor of IReadOnlyDictionary<string, object>

See original GitHub issue

Right now it’s a bit of a pain to use the Resolve method because what I’ll have in hand is an IReadOnlyDictionary<string, object>, usually from a method parameter.

Please consider adding this method and removing the nongeneric overload.

The nongeneric one would be a problem. So long as it’s there and you pass it a type like Dictionary<string, object> which implements both interfaces, which all of the BCL dictionaries do, you’ll have to disambiguate the overload by explicitly casting to one or the other interface type.

This would be a breaking change for people still using non-generic dictionaries like Hashtable, and there may be a few, so what if you removed it in v5?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:28 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
ghostcommented, Aug 22, 2018

@jnm2

The extension Arguments.FromReadOnlyDictionary now calls a shallow copy constructor here.

I think this coupled with making Arguments readonly for any side effects when it comes to calling Add, Clear or Remove by setting isReadOnly here gets you what you need.

It is also a tidy way of getting rid of bad methods as it turns out 😃

1reaction
jonorossicommented, Sep 27, 2017

@fir3pho3nixx thanks for looking into this more, I had just thought we’d do as @jnm2 suggested and implement it at the API surface level but this is something we’ll definitely need to look at more.

If Windsor does mutate the user’s dictionary then we could probably implement copy-on-write using the cheshire cat pattern or something similar so the Windsor internals are none the wiser that they were even passed a readonly dictionary.

However, we’ve already got copy-on-write with the overload that takes an anonymous type which Windsor obviously can’t modify, Windsor uses the ReflectionBasedDictionaryAdapter to read the contents and methods like Add throw a NotImplementedException, maybe some consolidation of code paths:

object Resolve(Type service, object argumentsAsAnonymousType);
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Extension methods for both IDictionary and ...
So if the OP wants to use the same extension method on both types of objects, he needs to write the method using...
Read more >
Why does IDictionary not implement IReadOnlyDictionary
2 Answers. Preface: this answer is predicated on a misunderstanding that IReadOnlyDictionary means "A dictionary that is read-only". It ...
Read more >
IReadOnlyDictionary<TKey,TValue> Interface
The IReadOnlyDictionary<TKey,TValue> interface allows the contained keys and values to be enumerated, but it does not imply any particular sort order. The ...
Read more >
Class SerializedDictionary<K, V> | Core RP Library | 15.0.6
Unity can't serialize Dictionary so here's a custom wrapper that does. ... before it can be serialized as Unity won't serialized generic-based types...
Read more >
Implementing a custom Trigger for an Isolated .Net Azure ...
For this post I wanted to research how to implement a custom trigger for Azure Functions running in the isolated process model.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found