# Viewmodelbuilder pattern declaration exception, why?

**URL:** <https://forum.litium.com/t/viewmodelbuilder-pattern-declaration-exception-why/2536>\
**Category:** Questions\
**Created:** [April 8, 2022, 2:18pm UTC](https://forum.litium.com/t/viewmodelbuilder-pattern-declaration-exception-why/2536 "2022-04-08T14:18:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mynameisandreas](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/mynameisandreas/32/282_2.png) [@mynameisandreas](https://forum.litium.com/u/mynameisandreas)\
**Post date:** [April 8, 2022, 2:18pm UTC](https://forum.litium.com/t/viewmodelbuilder-pattern-declaration-exception-why/2536/1 "2022-04-08T14:18:04Z")

</div>

Hi!  
You have an interface that looks like this

```auto
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:

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

```

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

```auto
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

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [April 10, 2022, 9:28am UTC](https://forum.litium.com/t/viewmodelbuilder-pattern-declaration-exception-why/2536/2 "2022-04-10T09:28:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mynameisandreas](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/mynameisandreas/32/282_2.png) [@mynameisandreas](https://forum.litium.com/u/mynameisandreas)\
**Post date:** [April 10, 2022, 9:45pm UTC](https://forum.litium.com/t/viewmodelbuilder-pattern-declaration-exception-why/2536/3 "2022-04-10T21:45:22Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [May 8, 2022, 9:45pm UTC](https://forum.litium.com/t/viewmodelbuilder-pattern-declaration-exception-why/2536/4 "2022-05-08T21:45:49Z")

</div>

Closed on May 8, 2022, 9:45pm UTC

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