I'm starting to use simpleject for dependency injection.
I created the BootStrapper class to register the containers:
public class BootStrapper
{
public static void RegisterServices(Container container)
{
container.Register<IRepository, Repository>(Lifestyle.Singleton);
container.Verify();
}
}
I created the SimpleInjectorInitializer class to start the simpleinject settings:
public class SimpleInjectorInitializer
{
public static void Initialize()
{
var container = new Container();
InitializeContainer(container);
container.Verify();
}
private static void InitializeContainer(Container container)
{
BootStrapper.RegisterServices(container);
}
}
At the start of the class I call:
SimpleInjectorInitializer.Initialize();
My variable is declared as
private readonly IRepository _Repository;
When I run the command:
Console.WriteLine("Teste" + _repository.SelecionarRegistroPorCommando("123"));
The compiler reports that it does not have an instance of the object.
class Program
{
static void Main(string[] args)
{
var test = new TesteIoC();
}
}
public class TesteIoC
{
private readonly IRepository _Repository;
public TesteIoC()
{
SimpleInjectorInitializer.Initialize();
Console.WriteLine("Teste" + _repository.SelecionarRegistroPorCommando("123"));
}
}