I'm a beginner on IoC and dependency injection. I'm reading about it, but I just can't get it. While I figure out how stuff works, I'm trying to implement some of these patterns on my project (and maybe learn by trial and error).
I'm implementing security control by using FluentSecurity package (from NuGet, btw). I need to implement a Policy Violation Handler, as described on this wiki. The problem is that the example is written for StructureMap IoC-container, and I'm using (or trying to) Ninject 2.2 (it seemed more simple for a beginner).
On their code, they suggest (a):
configuration.ResolveServicesUsing(type => ObjectFactory.GetAllInstances(type).Cast<object>());
And then (b):
public class WebRegistry : Registry
{
public WebRegistry()
{
Scan(scan =>
{
scan.TheCallingAssembly();
scan.AddAllTypesOf<IPolicyViolationHandler>();
});
}
}
My concerns:
- I know that code (a) will be included on
Global.asax
. But what is Ninject's alternative toObjectFactory.GetAllInstances()
? - I have no idea neither where this code should be inserted nor what are the equivalents for
WebRegistry
,Scan
, and the internal functionsTheCallingAssembly
andAddAllTypesOf
.
I know this is a bit extensive question, but I appreciate any help! Thanks in advance.