ninject

How to inject UserManager & SignInManager

强颜欢笑 提交于 2019-12-25 06:34:04
问题 I am trying to figure out how to inject UserManager and SignInManager. I have installed Ninject in my application and I am using it in the following manner: Please consider this to be a brand new project. Inside Startup.cs I have the following: public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); app.UseNinjectMiddleware(CreateKernel); } private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Load(Assembly

Ninject Interception 3.0 Interface proxy by method attributes

a 夏天 提交于 2019-12-25 06:26:29
问题 I have just upgraded a relatively large codebase from Ninject 2.2 to Ninject 3.0. Everything seems to be going as planned except I had to make a few changes to the interception stuff that we use. interface IFoo { Bar GetBar(); } class Foo : IFoo { [LogMethod(Level = LogLevel.Error)] public virtual Bar GetBar() { return new Bar(); } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] class LogMethodAttribute

Action filter constructor being called repeatedly for single controller

空扰寡人 提交于 2019-12-25 04:58:17
问题 I'm using an action filter on some of my controllers, irrelevant what it does, that uses Ninject for dependency injection. I set breakpoints in the controller constructor and the action filter constructor, and I found that for a single request, the controller's constructor gets called once and the action filter's 8 times. The following code produces the effect, virtually the same as that given in this answer. Attribute: public class NotificationAttribute : Attribute { } public class

Will my session be automatically closed?

天涯浪子 提交于 2019-12-25 04:37:19
问题 Edit Orignal Title: My transaction is closed by the time it gets to my Repo. What am I doing wrong? I got a answer to my origanl questions(I forgot to open the transaction lol). Now I am wondering if my code is automatically closing the session or if I have to somehow tell it to do this. Hi I am using mvc 3.0, nhibernate, fluent nhibernate and ninject 2.0 Global.asax // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801 public class

Compilation Error with Ninject

徘徊边缘 提交于 2019-12-25 04:35:13
问题 Ninject looks great, so I'd like to use it in my project. Unfortunately I am still struggling to do the most trivial binding. The [Inject] attribute compiles just fine, but the compiler cannot find the "Bind" command: using System; using Ninject.Core; using Ninject.Core.Binding; namespace NinjectTest { public interface IFoo { void DoSomething(); } public class Foo : IFoo { public void DoSomething() { throw new NotImplementedException(); } } public class Bar { [Inject] private IFoo theFoo;

NInject IBindingGenerator and ToProvider

半城伤御伤魂 提交于 2019-12-25 04:17:08
问题 I've created this code: public class AddonsModule : Ninject.Modules.NinjectModule { public override void Load() { this.Bind(b => b.FromAssembliesMatching("*") .SelectAllClasses() .InheritedFrom(typeof(UIExtensibility.AbstractAddon)) .BindWith(new AddonBindingGenerator()) ); } private class AddonBindingGenerator : IBindingGenerator { public System.Collections.Generic.IEnumerable<Ninject.Syntax.IBindingWhenInNamedWithOrOnSyntax<object>> CreateBindings(System.Type type, Ninject.Syntax

Ninject Activation Exception

╄→гoц情女王★ 提交于 2019-12-25 03:43:06
问题 I am using asp.net mvc 3. I am using ninject 2.2.1.0 protected void Application_Start() { // Hook our DI stuff when application starts SetupDependencyInjection(); } public void SetupDependencyInjection() { // Tell ASP.NET MVC 3 to use our Ninject DI Container DependencyResolver.SetResolver(new NinjectDependencyResolver(CreateKernel())); } protected IKernel CreateKernel() { var modules = new INinjectModule[] { new NhibernateModule(), new ServiceModule(), new RepoModule() }; return new

Ninject Named binding with IGenericRepository

僤鯓⒐⒋嵵緔 提交于 2019-12-25 03:21:49
问题 I'm developing an ASP.NET MVC 4 Web Api, with C#, .NET Framework 4.0, Entity Framework Code First 6.0 and Ninject. I have two different DbContext custom implementations to connect with two different databases. This is my NinjectConfigurator class (partial): private void AddBindings(IKernel container) { container.Bind<IUnitOfWork>(). To<TRZICDbContext>().InRequestScope().Named("TRZIC"); container.Bind<IUnitOfWork>(). To<INICDbContext>().InRequestScope().Named("INIC"); container.Bind

Ninject in a three tier application

风格不统一 提交于 2019-12-25 02:57:49
问题 I am building a standard three tier app. 1 Console app for front end 2 Business logic layer 3 Data layer The main purpose is to display some customer data from a database table. I'm trying to follow the guide lines in the book "Dependency Injection in .NET" by having no reference from the console to the data layer, and none from the business layer to the data layer. Allowing for easy swapping of the front end and the data layers if needed. Let's say I have a service at the business layer

Binding mediator (shortbus) with/to ninject

人盡茶涼 提交于 2019-12-25 01:43:48
问题 I am trying to use the mediator pattern with shortbus(https://github.com/mhinze/ShortBus). Everything goes great except binding it to ninject. There is a structuremap example like so public BasicExample() { ObjectFactory.Initialize(i => { i.Scan(s => { s.AssemblyContainingType<IMediator>(); s.TheCallingAssembly(); s.WithDefaultConventions(); s.AddAllTypesOf((typeof(IRequestHandler<,>))); s.AddAllTypesOf(typeof(INotificationHandler<>)); }); i.For<IDependencyResolver>().Use(() =>