I recently had a requirement to inject strings into a constructor argument using an IoC container such as Ninject.
Unfortunately, I had always used Ninject in the past to inject dependencies that were based on interfaces, so how was I supposed to inject primitive types such as strings?
Well, fortunately, using Ninject, it is surprisingly simple!!
I just used the following code:
That was all that was needed!!
Unfortunately, I had always used Ninject in the past to inject dependencies that were based on interfaces, so how was I supposed to inject primitive types such as strings?
Well, fortunately, using Ninject, it is surprisingly simple!!
I just used the following code:
kernel.Bind<IHttpClientWrapper>().To<HttpClientWrapper>().WithConstructorArgument("userName", "johndoe");
That was all that was needed!!
No comments:
Post a Comment