ninject

Ninject scope problems with TopShelf, Ninject and EF code first

岁酱吖の 提交于 2019-12-10 14:44:46
问题 I am currently using TopShelf with Ninject to create a Windows Service. I have the following code to setup the Windows Service using TopShelf: static void Main(string[] args) { using (IKernel kernel = new StandardKernel(new NinjectDependencyResolver())) { Settings settings = kernel.Get<Settings>(); var host = HostFactory.New(x => { x.Service<BotService>(s => { s.ConstructUsing(name => new BotService(settings.Service.TimeInterval)); s.WhenStarted(ms => ms.Start()); s.WhenStopped(ms => ms.Stop(

Unable to Create DbContext per Request with Simple Injector

别来无恙 提交于 2019-12-10 14:24:48
问题 Simple Inject is throwing the following exception when attempting to register my DbContext. The supplied connection string is not valid, because it contains insufficient mapping or metadata information. Parameter name: connectionString I'm new to DI and could be missing something fairly obvious. The connection string looks fine. It is the same one that gets used to create the DbContext normally. I was attempting the solution here public static class SimpleInjectorInitializer { /// <summary

Singleton Scope for EF's DbContext

喜你入骨 提交于 2019-12-10 13:58:09
问题 so I am currently working on an ASP.NET MVC web application that uses Entity Framework, I'm also using Ninject for Dependency Injection. So basically, at the moment, this is how I register my DbContext and Services with Ninject. kernel.Bind<DbContext>().To<MyApplicationContext>().InSingletonScope(); kernel.Bind<IAccountService>().To<AccountService>().InSingletonScope(); kernel.Bind<IRegionService>().To<RegionService>().InSingletonScope(); kernel.Bind<IRoleService>().To<RoleService>()

Ninject 2.0 - binding to a object that uses the same interface more than once?

最后都变了- 提交于 2019-12-10 13:37:20
问题 Consider the following: public Something(IInterface concreteObjectOne, IInterface concreteObjectTwo) { this.concreteObjectOne = concreteObjectOne; this.concreteObjectTwo = concreteObjectTwo; } How do I set set this type of binding up with Ninject? I'd try Googling the term, but as I'm not sure what this is called I can't, nor can I find anything on the Wiki about this. Edit : I believe this is called Convention Based Binding, as described here. However this documentation is for version 1.0

Using Ninject to Bind WebApi Filter Attributes

十年热恋 提交于 2019-12-10 13:29:24
问题 I'm currently using ninject.mvc3 in my asp.net webapi project, and it works fine. I am now trying to bind filter attributes, but BindFilter and BindHttpFilter are missing from IKernel interface when using the NinjectWebCommon static class method. If I add the Ninject.Web.WebApi package, its there but the project does not run (problem here, solution said that Ninject.Web.WebApi is deprecated) so I removed it back. I also followed this github wiki exactly and still this.BindFilter was not found

Ninject -> Scan assemblies for matching interfaces and load as modules

我与影子孤独终老i 提交于 2019-12-10 13:23:37
问题 In earlier versions of Ninject.Extensions.Conventions, it was pretty easy to scan a directory for assemblies, filter classes by interface and then load all containing ninject modules. kernel.Scan(scanner => scanner.FromAssembliesInPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)) scanner.AutoLoadModules(); scanner.WhereTypeInheritsFrom<IPlugin>()); public class MyPlugin : NinjectModule, IPlugin { public override void Load() { Bind<IRepositoryFromPluginHost>().To

When is a Transient-scope object Deactivated in Ninject?

北城以北 提交于 2019-12-10 13:02:07
问题 When an object in Ninject is bound with InTransientScope() , the object isn't placed into the cache, since it's, er, transient and not scoped to anything. When done with the object, I can call kernel.Release(obj) ; this passes through to the Cache where it retrieves the cached item and calls Pipeline.Deactivate using the cached entry. But since transient objects aren't cached, this doesn't happen. I haven't been able to figure out where (or who) performs the deactivation for transient objects

Singleton Scope binding not working as intended

浪尽此生 提交于 2019-12-10 12:46:34
问题 I am using the ninject mvc3 plugin with my web api application. I have a binding that looks like: kernel.Bind<IFoo>().To<Foo>().InSingletonScope(); It is my interpretation that the kernal will create exactly one instance of Foo and reuse it appropriately. By putting a breakpoint in Foo 's constructor, I can clearly see that it is getting called once per request, and I cannot explain why. My only guess is that somehow a new kernel is getting created per request, but that doesn't appear to be

“Server Error in '/' Application. Sequence contains no elements” after refactoring namespace

こ雲淡風輕ζ 提交于 2019-12-10 12:43:13
问题 I'm using MVC 4 and Ninject 3 with NinjectWebCommon in the App_Start folder. And my Global.asax.cs is MvcApplication : HttpApplication I'm getting the error below because the Ninject is starting twice - Why? Server Error in '/' Application. Sequence contains no elements Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System

Convention Based Dependency Injection with Ninject 3.0.0

倖福魔咒の 提交于 2019-12-10 12:43:04
问题 I have two projects in my solution... a domain project and MVC3 web project (e.g. MyApp.Domain and MyApp.Web). Previously, when using Ninject.Extensions.Conventions ver. 2, I was able to use the following statement in the NinjectMVC3.cs file, and required dependencies throughout my solution (both web and domain) were injected properly (e.g. IFoo automatically bound to Foo). kernel.Scan(x => { x.FromAssembliesMatching("*"); x.BindWith<DefaultBindingGenerator>(); }); I have just upgraded to