Skip to content

Conversation

@patsissons
Copy link

I am creating this PR because I ran into an issue yesterday where I wanted to make a generically typed view model that would all use a common view. The problem with this approach is that you cannot register your IViewFor<> associations because the generic type doesn't allow that (this might work if you use an IoC that supports generic registrations, I'm not entirely sure). The simplest solution I could think of was to allow overriding the type information used in view resolution by using a custom attribute. This attribute then supplies the type override to use in view resolution (and does not even necessarily have to be related to the view model it decorates, but that would probably be a strange setup).

Here are some examples where we could use this new attribute

[ViewResolutionTypeOverride(Type = typeof(IMyViewModel))]
public class MyGenericViewModel<T> : ReactiveObject, IMyViewModel
{
    // ...
}

public class MyBaseViewModel : ReactiveObject
{
    // ...
}

[ViewResolutionTypeOverride(Type = typeof(MyBaseViewModel))]
public class MyDerivedGenericViewModel<T> : MyBaseViewModel
{
    // ...
}

// and in the view registrations
public void RegisterViews()
{
    Locator.CurrentMutable.Register(() => MyView(), typeof(IViewFor<IMyViewModel>));
    Locator.CurrentMutable.Register(() => MyOtherView(), typeof(IViewFor<MyBaseViewModel>));
}

p.s. if a test is required for this PR to be accepted let me know and I'll look into writing a new test for it.

…esolveView function (this will make it easier to manipulate this type in a future commit)
… potentially override the viewModelType variable used in view resolution
@anaisbetts
Copy link
Member

I'm not sure that we need this because we have the contract parameter, does that work?

@patsissons
Copy link
Author

I couldn't think of a way to make the contract work elegantly. Do you have
an example I could take a look at?
On Jul 17, 2015 10:15 AM, "Paul Betts" [email protected] wrote:

I'm not sure that we need this because we have the contract parameter,
does that work?


Reply to this email directly or view it on GitHub
#904 (comment)
.

@moswald
Copy link
Contributor

moswald commented Dec 24, 2015

@patsissons:

[ViewContract(Contract = "Detailed")]
class MyDetailedView : IViewFor<MyViewModel>
[ViewContract(Contract = "Summary")]
class MySummaryView : IViewFor<MyViewModel>

See this completed PR for one way you might put it to use.

@patsissons
Copy link
Author

I'm not sure if this fully solves the issue I was facing way back then, but I don't really use RxUI these days so I can't really say for sure. That said I can probably close this PR now since it has become so stale.

@patsissons
Copy link
Author

closing this as it has become way too stale.

@patsissons patsissons closed this Feb 22, 2016
@ghuntley ghuntley modified the milestone: 7.0.0 Nov 6, 2016
@lock lock bot locked and limited conversation to collaborators Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants