TypedMVVM: Adding a new IoC.Container class for generating instances using generics

In the previous days I was extending my TypedMVVM library with additional classes for separating the logic and being able to use different services for handling operations like showing message dialogs.

I’ve then started the implementation of a simple IoC.Container class that will manage in a centralized way the creation of new objects (ViewModels, Services, etc.) used by the application.

The first step was the creation of a simple Resolve<T> method for creating instances using the concept of Generics available in TypeScript.

When working with factories and generics, it’s necessary to refer to class types using their constructor function:

In this way, a new instance of type T will be returned each time the function IoC.Container.resolve will be used.

For example, it’s now possible to inject a service on a ViewModel in this way:

I’m planning for the future more functionalities for this IoC.Container class, like the possibility to register specific services with interfaces and use them as singletons.

The updated code is available for download from the repository here.