Blogs Hub

by AskGif | Mar 23, 2019 | Category :coding

Using Moq to Mock Entity Framework DBSet objects

Using Moq to Mock Entity Framework DBSet objects

Unit testing in .NET is pretty nice when your dependency injection/IoC is set up well, but Entity Framework 6 isn’t the nicest framework for mocking and testing. If you’re using ASP.NET MVC 5, you may have run into this scenario.   Problem: You want to use or mock

read more...

by AskGif | Mar 21, 2019 | Category :coding

Ninject InSingletonScope still creates new objects

Ninject InSingletonScope still creates new objects

Me: Kernel.Bind<IDataCache>().To<InMemoryDataCache>().InSingletonScope(); Ninject: Haha, nah. Here’s a new object bro. I don’t know why exactly this happens but for some reason, I’ve seen it happen in more than one project. Binding an implemen

read more...

by AskGif | Mar 21, 2019 | Category :coding

Correct way to Inject MVC and HTTP attributes and filters using Ninject

Correct way to Inject MVC and HTTP attributes and filters using Ninject

Ninject has some fun quirks. For instance, one "bug" I came across was that if you hit an ASP.NET controller with a custom attribute, the attribute&rsquo;s constructor-injected dependencies would be null on startup. For example, take the following ActionFilterAttribute: <pre class="language-

read more...

by AskGif | Mar 21, 2019 | Category :coding

Ninjecting in App_Start classes and static classes

Ninjecting in App_Start classes and static classes

Let's say you are doing some work on your AuthConfig class, in your Global.asax, or maybe a static class. You can&rsquo;t property-inject, and generally, it&rsquo;s a pain to get this to work. &nbsp; However, if you&rsquo;re using Ninject for ASP.NET MVC, you can use the following

read more...