# How to use VariantService in a windows application

**URL:** <https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713>\
**Category:** Questions\
**Tags:** litium-8\
**Created:** [October 10, 2022, 11:16am UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713 "2022-10-10T11:16:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokul](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@Gokul](https://forum.litium.com/u/Gokul)\
**Post date:** [October 10, 2022, 11:16am UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/1 "2022-10-10T11:16:16Z")

</div>

We have a windows application where we should be able to use the VariantService from Litium.Products, but the service seems to be not getting resolve successfully.

“InvalidOperationException: Unable to resolve service for type ‘Litium.Products.VariantService’ while attempting to activate ‘IntegrationService.Services.ProductService’.”

if I add service as below it gives another error "‘Cannot instantiate implementation type ‘Litium.Products.VariantService’ for service type ‘Litium.Products.VariantService’.’  
"

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/4d1e1ae537a34eb2611edd8eaf4808869a429c44.png)

is there anyway to do it?

Litium version: 8.5

---

<div class="post-metadata">

**Author:** ![steve.redstorm](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/steve.redstorm/32/14_2.png) [@steve.redstorm](https://forum.litium.com/u/steve.redstorm)\
**Post date:** [October 10, 2022, 12:36pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/2 "2022-10-10T12:36:34Z")

</div>

Variant service inherits from IEntityService so you need to add that also

> public abstract class VariantService : IEntityService

and the base looks like this:

> [Service(ServiceType = typeof(IEntityService\<\>), Lifetime = DependencyLifetime.Singleton)]  
> public interface IEntityService  
> where T : IEntityKey

---

<div class="post-metadata">

**Author:** ![Gokul](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@Gokul](https://forum.litium.com/u/Gokul)\
**Post date:** [October 10, 2022, 12:57pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/3 "2022-10-10T12:57:31Z")

</div>

tried both below but still seems to get resolve errors.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/7ec1f0a7d3049f82ce3f2e7bffcdd30874822bd0.png)

‘Cannot instantiate implementation type ‘Litium.Data.Internal.IEntityService`1[Litium.Products.Variant]' for service type 'Litium.Data.Internal.IEntityService`1[Litium.Products.Variant]’.’

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/902a6ddad2fb13a369bb6e6ebeb4f00a2bf748b9.png)

‘Cannot instantiate implementation type ‘Litium.Data.Internal.IEntityService`1[T]' for service type 'Litium.Data.Internal.IEntityService`1[T]’.’

same error if I use as Singleton.

---

<div class="post-metadata">

**Author:** ![steve.redstorm](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/steve.redstorm/32/14_2.png) [@steve.redstorm](https://forum.litium.com/u/steve.redstorm)\
**Post date:** [October 10, 2022, 1:04pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/4 "2022-10-10T13:04:52Z")

</div>

How about this:

> services.AddScoped\<IEntityService\<Litium.Products.VariantService\>, Litium.Products.VariantService\>();

---

<div class="post-metadata">

**Author:** ![Gokul](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@Gokul](https://forum.litium.com/u/Gokul)\
**Post date:** [October 10, 2022, 1:18pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/5 "2022-10-10T13:18:33Z")

</div>

modified it a bit as

services.AddScoped\<IEntityService\<Litium.Products.Variant\>, Litium.Products.VariantService\>();

and getting below error.

‘Cannot instantiate implementation type ‘Litium.Products.VariantService’ for service type ‘Litium.Data.Internal.IEntityService`1[Litium.Products.Variant]’.’

---

<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:** [October 10, 2022, 1:21pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/6 "2022-10-10T13:21:26Z")

</div>

The `Litium.Products.VariantService` is the contract and for that the implementation need to be registrated so it is not so simple.

The implementation is dependent on a lot of other services, caching, configuration etc and to make it startup correctly you will add them with the `services.AddLitiumApplication(Configuration);`, this exists in the Litium.Application assembly. When adding the `services.AddLitiumApplication(Configuration)` into the services, the full Litium platform will be executed inside this application and not sure if that is what you want.

---

<div class="post-metadata">

**Author:** ![Gokul](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@Gokul](https://forum.litium.com/u/Gokul)\
**Post date:** [October 10, 2022, 2:01pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/7 "2022-10-10T14:01:59Z")

</div>

is there any other way to just use the variant service? using something similar to IoC.Resolve ?

---

<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:** [October 10, 2022, 2:19pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/8 "2022-10-10T14:19:03Z")

</div>

No, it’s not.

The implementation of variant service (or other service) in Litium is dependent or the full platform running in the same context.

---

<div class="post-metadata">

**Author:** ![Gokul](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@Gokul](https://forum.litium.com/u/Gokul)\
**Post date:** [October 10, 2022, 2:31pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/9 "2022-10-10T14:31:14Z")

</div>

tried to add services.AddLitiumApplication(Configuration); but then I get error to add all the services highlighted, and still it fails if I add all those "‘Cannot instantiate implementation type ‘Litium.Connect.Shipments.ShippingProviderService’ for service type ‘Litium.Connect.Shipments.ShippingProviderService’.’  
"

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/ff62c342e8891d75f3908279befd1b63d69a6be9.png)

---

<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:** [October 10, 2022, 3:15pm UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/10 "2022-10-10T15:15:28Z")

</div>

As for the VariantService, you can’t add the contract (abstract class) as the type for the service implementation and that is what you are doing with the yellow marked lines.

To solve that you have two options and both of them includes that you should remove the AddScoped-lines above and:

1. Remove the Litium.Connect.Abstractions assembly in the configuration for plugins
2. Add a package reference to Litium.Connect.Application

---

<div class="post-metadata">

**Author:** ![Gokul](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@Gokul](https://forum.litium.com/u/Gokul)\
**Post date:** [October 11, 2022, 5:58am UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/11 "2022-10-11T05:58:54Z")

</div>

1. Removed Litium.Connect.Abstractions assembly  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/5cad1fa3ab0daaf10d8b11eb04f2be5b11ce61e5.png)

2. Added package reference to Litium.Connect.Application

only having this in start up now  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/4dab08294252366c918d27d5982e94dce02a26cf.png)

it leads to an error “InvalidOperationException: Unable to resolve service for type ‘Microsoft.AspNetCore.Hosting.Server.IServer’ while attempting to activate ‘Litium.Application.Web.ServerListenerHelperServiceImpl’.” is there something I am missing?

---

<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:** [October 11, 2022, 8:45am UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/12 "2022-10-11T08:45:14Z")

</div>

Are you using the `Host.CreateDefaultBuilder(args)` as the builder or are you trying to bootstrap the host process as well?

---

<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:** [November 8, 2022, 8:45am UTC](https://forum.litium.com/t/how-to-use-variantservice-in-a-windows-application/2713/13 "2022-11-08T08:45:41Z")

</div>

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