Skip to content
This repository has been archived by the owner on Feb 14, 2022. It is now read-only.

Exceptions

Jacopo edited this page Mar 7, 2021 · 2 revisions

Exceptions

Table of Contents

StackInjectorException

The base exception class from which every other custom exception inherits.

Not found

ImplementationNotFoundException

Thrown when an implementation for an interface has not been found.

Also thrown when versioning and a valid version is not found.

solution: implement the interface.

ServiceNotFoundException

Thrown when a type for a service has not been found.

The class or interface you wanted as served is not in a registered assembly.

Probably caused when you're using multiple projects.

solution: modify the settings to register the assembly of the service you want.

var settings = StackWrapperSettings.Default
    .RegisterAssemblyOf<MyService>();

Injector.From<Something>(settings); // ...

Injection

NotAServiceException

Thrown when the specified class is NOT marked with [Service] attribute

cause:

class MyService {}

solution:

[Service] // add the attribute
class MyService {}

note: you could also disable strict checks in settings, but it's not suggested.

MissingParameterlessConstructorException

Thrown when a class has no parameterless constructor to call.

cause:

[service]
class MyService 
{
    public MyService (int par) 
    {  
        // stuff
    }
}

solution:

[service]
class MyService 
{

    public MyService () {} // add default constructor

    public MyService (int par) // you could've also removed this.
    {  
        // stuff
    }
}

NoSetterException

Thrown when the specified type has a field/property without a setter

cause:

[service]
class MyService 
{
    [Served]
    MyOtherService service {get;}
}

solution:

[service]
class MyService 
{
    [Served]
    MyOtherService service {get; set;}
}

note: you can add a setter to readonly properties and injection will still work.

InvalidEntryTypeException

Thrown when the entry point is invalid.

causes:

// SOLUTION: AlwaysCreate is not a valid pattern for an entry point
[Service(Pattern = InstantiationPattern.AlwaysCreate)]
private class InvalidEntryTypeThrower { }
  • trying to get an entry of a non-injected StackWrapper.