ninject-extensions

Ninject and OnePerRequestModule

你。 提交于 2019-12-22 03:49:39
问题 I have recently tried out Ninject with the Ninject.Web.Mvc extension, and I've noticed something peculiar and, while not breaking, confusing. In the NinjectHttpApplication abstract class, there is a constructor defined as follows.. /// <summary> /// Initializes a new instance of the <see cref="NinjectHttpApplication"/> class. /// </summary> protected NinjectHttpApplication() { this.onePerRequestModule = new OnePerRequestModule(); this.onePerRequestModule.Init(this); } I have placed a debugger

Ninject Conventions with Ninject Factory Extension To Bind Multiple Types To One Interface

霸气de小男生 提交于 2019-12-20 04:54:10
问题 I'm trying to expand on the scenario asked in the SO question titled Ninject Factory Extension Bind Multiple Concrete Types To One Interface by using Ninject Conventions for convention-based binding of the ICar implementations. I'm working off the accepted answer authored by Akim and his Gist outlining the full example. The difference is that I've replaced the explicit ICar bindings with convention-based bindings (or an attempt at it, at least ;) public class CarModule : NinjectModule {

Upgrading Ninject/Ninject WCF Extensions to the latest version 3.0.0.5

孤街醉人 提交于 2019-12-18 04:46:11
问题 I am currently using Ninject (2.2.1.4) and Ninject.Extensions.Wcf (2.2.0.4) with my WCF service. I would like to upgrade to Ninject (3.0.0.15) and Ninject.Extensions.Wcf (3.0.0.5) and it doesn't look like I can use my current approach anymore. Can anyone point me to some samples or posts on how to get the latest version of Ninject working with a WCF project. My current approach: I wrote a module: public class NinjectDependencyResolver : NinjectModule { public override void Load() { // Declare

Ninject and ChildKernel in MVC3 project: “Error loading Ninject component ICache”

て烟熏妆下的殇ゞ 提交于 2019-12-14 03:12:15
问题 I'm using Ninject (3.0) in my ASP.Net MVC3 project. At some point of request handling I want to execute some tasks. I'm using session-per-request pattern but don't want these tasks to share the same Session as current Request has. So, I thought, ChildKernels could help me with this issue. I was going to create another binding for ISession in child kernel, but started with that: var child = new Ninject.Extensions.ChildKernel.ChildKernel(NinjectMVC3.Kernel); child.Dispose(); If I execute the

Ninject Binding by Convention not working with generics types

纵饮孤独 提交于 2019-12-12 14:11:52
问题 I am using .NET 4.5, Ninject 3 with the binding by convention lib as follow: kernel.Bind(x => x .FromAssembliesMatching("assembly.dll") .SelectAllClasses().InheritedFrom(typeof(ICommandHandler<>)) .BindAllInterfaces()); And this is binding properly for: public class MyCommandHandler : ICommandHandler<MyCommand> But doesn't bind: public class MyGenericCommandHandler<T> : ICommandHandler<MyGenericCommand<T>> However, the previous binding works if I add individual bindings for specific

Ninject factory extension and InCallScope does not give expected results

白昼怎懂夜的黑 提交于 2019-12-10 21:23:55
问题 I am struggling with using the factory extensions for Ninject. When using the extension in combination with InCallScope, I expected the same instance to be returned from the factory's create method, but instead I get two different instances. Have I misunderstood the InCallScope concept or do I need to add something else? using System; using Ninject; using Ninject.Extensions.Factory; using Ninject.Extensions.NamedScope; namespace MyTest { class Program { static void Main() { var kernel = new

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

Ninject.Extensions.Logging.Log4net unexpected behavior

可紊 提交于 2019-12-09 11:57:57
问题 I am having a problem using Log4Net (1.2.10) through Ninject's (2.2.1.4) Extensions.Logging.Log4net (2.2.0.4), as installed through NuGet. When I access Log4Net directly: var logger = log4net.LogManager.GetLogger("Log4NetLoggerTest"); logger.Debug("foo { bar"); The result is: 2011-08-29 10:02:02,071 [9] DEBUG Log4NetLoggerTest foo { bar However, when the logger is accessed through Ninject: using (IKernel kernel = new StandardKernel()) { var ninjectLogger = kernel.Get<NinjectLoggerTest>();

Ninject: How to access root object of NamedScope from factory

試著忘記壹切 提交于 2019-12-08 00:10:46
问题 In my application I am using Ninject and the NamedScopeExtension. One of the objects deeper in the object graph needs access to the root object that defined the named scope. It seems to me that DefinesNamedScope() does not also imply InNamedScope() and instead a new root object is created when I request the root. Example: using System; using Ninject; using Ninject.Extensions.NamedScope; using Ninject.Syntax; namespace NInjectNamedScope { public interface IScopeRoot { Guid Guid { get; } void

Ninject: How to access root object of NamedScope from factory

好久不见. 提交于 2019-12-06 12:35:59
In my application I am using Ninject and the NamedScopeExtension. One of the objects deeper in the object graph needs access to the root object that defined the named scope. It seems to me that DefinesNamedScope() does not also imply InNamedScope() and instead a new root object is created when I request the root. Example: using System; using Ninject; using Ninject.Extensions.NamedScope; using Ninject.Syntax; namespace NInjectNamedScope { public interface IScopeRoot { Guid Guid { get; } void DoSomething(); } public interface IFactory { Guid Guid { get; } IOther CreateOther(); } public interface