Viewmodelbuilder pattern declaration exception, why?

Hi!
You have an interface that looks like this

public interface IViewModelBuilder<T> where T : IViewModel
    {
    }

You are using this (im guessing) to register all ViewModelbuilders.
The generic type is here declarated to be of type IViewModel.
So far so good, straight forward im with you.
But when we come to the HeadViewModelBuilder (as one example) you have declarated it as below:

public class HeadViewModelBuilder<TViewModel> : IViewModelBuilder<TViewModel>
        where TViewModel : HeadViewModel

but I don’t see why it’s not just

public class HeadViewModelBuilder : IViewModelBuilder<HeadViewModel>

Like almost every other ViewModelBuilder.
So why is there a declaration like this for this one and a few others, why are there a few exception from the rest of the viewmodel builders?

Litium version: 8.3.0

As the code in accelerator is build today we don’t have a need; except service registration, for having the IViewModelBuilder because we are always injecting the correct type of the builder in their usage.

For the specific example the code is multiple years old and I don’t remember all small details from that time but I guess that it was because of we having multiple headers, small and large, and there was created with a common base class like SmallHeadViewModel : HeadViewModel and LargeHeadViewModel : HeadViewModel so the result can be different from the same builder that was using the correct type through AutoMapper.

Thank you Patric! Old code works as a perfect answer! Good to know when we are making changes if it’s old stuff or moving to newer stuff!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.