02. Referencing Inity Assemblies

  02. Installation No Comments

To reference code in Inity from your own code you need to create assembly definition assets in the roots of your script folders and add references to the Inity assemblies that contain the scripts you want to use.

Inity contains four assemblies that you can reference in your code:

  1. Inity – The main assembly that contains most classes including MonoBehaviour<T>.
  2. Inity.Interfaces – Assembly containing all interfaces such as IInitializable<T>.
  3. Inity.Services – This contains only two attributes: ServiceAttribute and the EditorServiceAttribute. The reason that these attributes have been isolated to their own assembly is for performance reasons (more on that later).
  4. Inity.Editor – Editor-only assembly containing classes related to unit testing as well as custom editors and property drawers for the inspector.

Recommended Assembly Setup

In most cases you will only need to use classes found in the Inity and in some cases the Inity.Interface assemblies, so add references to those to your assembly definition assets as needed. The assembly where you will have all your components that inherit from MonoBehaviour<T…> will need to reference at least the Inity assembly.

The Inity.Editor assembly you should only reference from your own Editor-only assemblies. This might be useful when writing unit tests, if you want to utilize the Testable class or .

For optimal performance it is recommended, if possible, to isolate all your service classes to their own assembly. If you manage to pull this off, then this assembly will be the only one that needs to reference the Inity.Services assembly. During initialization Inity uses reflection to scan all classes in assemblies that reference Inity.Services assembly, so the less classes there are to examine the faster this will be.

Since two-way references between assembly definition assets are not allowed, this will likely mean in practice that you can not directly references any classes contained in the assembly that houses your services. While this might seem like an insurmountable obstacle at first, it can also be a blessing in disguise, since it effectively forces you to decouple all your services from their actual implementations. You can pull this off by adding all your interfaces into their own assembly, having all your services implement one of these interfaces, and then interact with your services through these interfaces instead of referencing the classes directly.

You can take a look at the Demo project as an example of how to organize your scripts in the recommended manner.

Sisus.Inity Namespace

To reference code in Inity you also need to add the following using directive to your classes:

using Sisus.Inity;

Leave a Reply

Your email address will not be published. Required fields are marked *