Dependency Injection

Registration of the rules, production rules, Token factories and Assemblies used by AboditNLP is accomplished using a dependency injection container. Currently there is an adapter for Autofac, others can easily be added.

An interface INLPPart is provided to make registration easy, for Autofac:

// A LexemeStore is a place to store words and their meanings
builder.RegisterType<LexemeStore>().SingleInstance()
   .AsImplementedInterfaces();

// NLP should be registered as SingleInstance as it requires 
// a lot of memory and many structures in it are static
builder.RegisterType<NLP>().SingleInstance()
   .AsImplementedInterfaces();

// Register all of the ITokenFactory, ILexemeStore and INLPRule
// classes in all relevant assemblies.
// The interface INLPPart is provided to make this convenient
// (and future proof)

// The NLP assembly contains many Production Rules and some
// TokenFactories that need to be registered
builder.RegisterAllNlpParts(typeof(NLP).Assembly);

// Do the same for each of your assemblies containing rules
builder.RegisterAllNlpParts(...)...

Note that If you are using the optional Wordnet extension you need to register it too; here we do that using one of the interfaces or classes from it: e.g. a_cappella1 or W00.

// Assembly containing Wordnet
builder.RegisterAllNlpParts(typeof(AboditNLP.W00).Assembly);