ninject

Ninject conditional binding based on parameter type

风格不统一 提交于 2019-12-21 04:14:41
问题 I'm using a factory to return a datasender: Bind<IDataSenderFactory>() .ToFactory(); public interface IDataSenderFactory { IDataSender CreateDataSender(Connection connection); } I have two different implementations of datasender (WCF and remoting) which take different types: public abstract class Connection { public string ServerName { get; set; } } public class WcfConnection : Connection { // specificProperties etc. } public class RemotingConnection : Connection { // specificProperties etc.

Ninject.MVC3, Pass DependencyResolver to service-layer?

懵懂的女人 提交于 2019-12-21 03:56:41
问题 In a MVC3-application with Ninject.MVC 2.2.0.3 (after merge), instead of injecting repostories directly into controllers I'm trying to make a service-layer that contain the businesslogic and inject the repostories there. I pass the ninject-DependencyResolver to the service-layer as a dynamic object (since I don't want to reference mvc nor ninject there). Then I call GetService on it to get repositories with the bindings and lifetimes I specify in NinjectHttpApplicationModule. EDIT: In short,

Ninject logger using NLog

天涯浪子 提交于 2019-12-21 03:38:20
问题 I've just started learning Ninject but have come across a problem with the logger. I've currently got a controller that has a service and logger injected into the constructor like so: public ToolsController(IToolsService toolsService, ILogger logger) { logger.Info("ToolsController Created"); this.toolsService = toolsService; this.logger = logger; } The problem is on the logger.Info line (for example) in the constructor which seems to use the wrong logger, so the logger name it prints out is

How do I work with Ninject in an ASP.NET MVC Web App?

强颜欢笑 提交于 2019-12-21 03:25:27
问题 I've created a new MVC Web application and I have references to Ninject.dll, Ninject.Web.Common.dll and Ninject.Web.MVC.dll. Global.asax.cs: public class MvcApplication : NinjectHttpApplication { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", /

injecting viewmodel class without parameterless constructor in WPF with NInject

混江龙づ霸主 提交于 2019-12-21 02:41:10
问题 I'm using NInject to resolve the dependency for my first WPF application. Following are my code snippets. My App.xaml.cs goes like. public partial class App : Application { private IKernel container; protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); ConfigureContainer(); ComposeObjects(); } private void ComposeObjects() { Current.MainWindow = this.container.Get<MainWindow>(); } private void ConfigureContainer() { this.container = new StandardKernel(); container.Bind

Appropriate Repository LifeCycle Scope w/ Ninject in MVC

风流意气都作罢 提交于 2019-12-21 02:35:22
问题 What is the appropriate LifeCycle Scope for a repository and the EF context when using Entity Framework 4 with Ninject in an MVC 3 application? I've been using the default of InTransientScope, but questioning whether it should be InRequestScope. public class MyController: Controller { private readonly IMyRepo _repo; public MyController(IMyRepo repo) { _repo = repo; } public ActionResult Index() { var results = _repo.GetStuff(); return View(results); } } Ninject Module: public class MyServices

Ninject and ASP.NET Identity 2.0

此生再无相见时 提交于 2019-12-20 21:55:34
问题 I just upgraded the ASP.NET Identity Entity Framework package from 1.0 to 2.0 and one of the Ninject bindings is now broken: kernel.Bind<IUserStore<User>>().To<UserStore<User>>(); kernel.Bind<UserManager<User>>().ToSelf(); kernel.Bind<IRoleStore<IdentityRole>>().To<RoleStore<IdentityRole>>(); kernel.Bind<RoleManager<IdentityRole>>().ToSelf(); The second last one is giving this error on compile: The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' cannot be used as type parameter

Ninject and ASP.NET Identity 2.0

烈酒焚心 提交于 2019-12-20 21:55:10
问题 I just upgraded the ASP.NET Identity Entity Framework package from 1.0 to 2.0 and one of the Ninject bindings is now broken: kernel.Bind<IUserStore<User>>().To<UserStore<User>>(); kernel.Bind<UserManager<User>>().ToSelf(); kernel.Bind<IRoleStore<IdentityRole>>().To<RoleStore<IdentityRole>>(); kernel.Bind<RoleManager<IdentityRole>>().ToSelf(); The second last one is giving this error on compile: The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' cannot be used as type parameter

Injecting AutoMapper dependencies using Ninject

天涯浪子 提交于 2019-12-20 20:00:13
问题 I am having trouble injecting AutoMapper into an ASP.NET MVC 2 application using Ninject. I used Jimmy Bogard's post on AutoMapper and StructureMap type Configuration as a guide. public class AutoMapperModule : NinjectModule { public override void Load() { Bind<ITypeMapFactory>().To<TypeMapFactory>(); Bind<Configuration>().ToSelf().InSingletonScope().WithConstructorArgument("mapper", MapperRegistry.AllMappers); Bind<IConfiguration>().To<Configuration>(); Bind<IConfigurationProvider>().To

Dependency injecting UserStore in OWIN startup using Ninject OWIN middleware

南楼画角 提交于 2019-12-20 08:24:28
问题 I am having problems creating a custom UserStore using dependency injection when creating an ApplicationUserManager using the OWIN request pipeline. Background I am trying to migrate the user functionality in our web application from using the SimpleMembership to the new ASP.NET Identity. When starting a new MVC 5 project, the default implementation of the single page application uses ASP.Identity, using Entity Framework to implement the UserStore functionality. In my case, we are already