Nancy: How to avoid create instance of Generic Module

Created on 18 Aug 2017  ·  3Comments  ·  Source: NancyFx/Nancy

We create a generic module (BaseModule) to re-use in many others modules
The problem is Nancy are throw exception when trying create instance of BaseModule because it is generic type

How we can avoid this ?

Most helpful comment

Make your generic module abstract

All 3 comments

@ndphuong I havn't checked this but you can try overriding the module registration to specify what modules you actually want registered:

protected override IEnumerable<ModuleRegistration> Modules
{
    get
    {
        return base.Modules.Where(m => m.ModuleType == typeof(GenericBase<YourType>));
    }
}

Make your generic module abstract

Great tip @thecodejunkie

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Radzhab picture Radzhab  ·  11Comments

lgabryel picture lgabryel  ·  7Comments

thecodejunkie picture thecodejunkie  ·  8Comments

thecodejunkie picture thecodejunkie  ·  4Comments

mylemans picture mylemans  ·  9Comments