Question

I have found this post Replace Ninject with Simple Injector

but havent found the solution for following migrations. With Ninject:

public class ServiceClass : IServiceClass
...
IKernel kernel
...
this.kernel.Bind<IServiceClass>().ToMethod(context => this);

I try to use this construction with Simple Injector:

public class ServiceClass : IServiceClass
   ...
   Container container
   ...
   this.container = container;
   this.container.Register<IServiceClass>(() => container.GetInstance<ServiceClass >());

is it equal to Ninject one?

The second part in Ninject is:

public void BindSomeCallback(DelegateNumberOne delegateNumberOne)
{        
   this.kernel.Rebind<DelegateNumberOne>().ToConstant(delegateNumberOne);
}

to:

public void BindSomeCallback(DelegateNumberOne delegateNumberOne)
{ 
   this.container.Register<DelegateNumberOne, delegateNumberOne>();
}
Was it helpful?

Solution

is it equal to Ninject one?

Nope. This is:

this.container.Register<IServiceClass>(() => this);

But since you're actually registering a singleton, you can better write it as follows:

this.container.RegisterSingle<IServiceClass>(this);

The second part in Ninject is:

Again here, you want to register a delegate as singleton:

this.container.RegisterSingle<DelegateNumberOne>(delegateNumberOne);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top