ninject

Setup filter attribute for dependency injection to accept params in constructor

陌路散爱 提交于 2019-12-30 04:42:06
问题 I'm following a ninject filter attribute setup on this page. For them, they have: .WithConstructorArgumentFromControllerAttribute<LogAttribute>( "logLevel", attribute => attribute.LogLevel); The second parameter is expecting a Func<LogAttribute, object> callback . Their actual param list is setup as follows: Log(LogLevel = Level.Debug) But my filter attribute is setup as follows: public class AuthAttribute : FilterAttribute { } public class AuthFilter : IAuthorizationFilter { private readonly

Configuring Ninject for a console application and leveraging the existing repository for my MVC application

女生的网名这么多〃 提交于 2019-12-30 00:57:11
问题 I have a MVC 3 solution configured with Ninject using a repository pattern. Some of my bindings include: kernel.Bind<IDatabaseFactory>().To<DatabaseFactory>().InRequestScope(); kernel.Bind<IUnitOfWork>().To<UnitOfWork>().InRequestScope(); kernel.Bind<IMyRepository>().To<MyRepository>().InRequestScope(); kernel.Bind<IMyService>().To<MyService>().InRequestScope(); kernel.Bind<ILogging>().To<Logging>().InSingletonScope(); I also added a console application to my solution and I want to leverage

Resolving dependencies in OWIN WEB API Startup.cs with ninject

…衆ロ難τιáo~ 提交于 2019-12-29 18:43:52
问题 I have a Web Api 2 App, with two classes that both depend on another class, and i'm using ninject to resolve the dependancies. public class AuthorizationServerProvider : OAuthAuthorizationServerProvider { private IUserService _userService; public AuthorizationServerProvider(IUserService userService) { _userService = userService; } } public class RefreshTokenProvider : IAuthenticationTokenProvider { private IUserService _userService; public RefreshTokenProvider(IUserService userService) {

Ninject passing in constructor values

妖精的绣舞 提交于 2019-12-29 05:55:29
问题 With Ninject, how do you configure the kernel so I can define what constructor values are passing into the instantiation of an object? I have the following configured in a module: Bind<IService1>() .To<Service1Impl>() .InSingletonScope() .Named("LIVE"); Bind<IService2>() .To<Service2Impl>() .InSingletonScope() .Named("LIVE") .WithConstructorArgument( "service1", Kernel.Get<IService1>("LIVE")); Service2Impl takes a constructor parameter of IService1 but I want this to come from the container.

Inject a dependency into a custom model binder and using InRequestScope using Ninject

落花浮王杯 提交于 2019-12-28 04:25:28
问题 I'm using NInject with NInject.Web.Mvc. To start with, I've created a simple test project in which I want an instance of IPostRepository to be shared between a controller and a custom model binder during the same web request. In my real project, I need this because I'm getting IEntityChangeTracker problems where I effectively have two repositories accessing the same object graph. So to keep my test project simple, I'm just trying to share a dummy repository. The problem I'm having is that it

How can i do this better using Ninject IOC

好久不见. 提交于 2019-12-25 16:54:35
问题 the concept is quite popular but I have not found the answer yet. I have the following class structure public interface IMessage { } public class MessageA : IMessage { } public class MessageB : IMessage { } public interface IMessageHandler<T> where T : IMessage { void Handle(TMessage message); } public interface MessageAHandler : IMessageHandler<MessageA> { } public interface MessageBHandler : IMessageHandler<MessageB> { } public class MessageProcessor { public void Process(IMessage) { if

bind to property always return null

馋奶兔 提交于 2019-12-25 09:59:33
问题 I am trying to bind a repository to property using Ninject but always get null reference of binding object. I will explain the problem using code below. public interface IServiceRepository { User GetUser(string email); IQueryable<Statistic> GetStatisticForCurrentMonth(string ip); void InsertStatistic(ConversionModel conversionModel); class ServiceRepository : IServiceRepository { //Implementation of the Interface } I am would like to bind the repository above to class below while the class is

bind to property always return null

♀尐吖头ヾ 提交于 2019-12-25 09:57:27
问题 I am trying to bind a repository to property using Ninject but always get null reference of binding object. I will explain the problem using code below. public interface IServiceRepository { User GetUser(string email); IQueryable<Statistic> GetStatisticForCurrentMonth(string ip); void InsertStatistic(ConversionModel conversionModel); class ServiceRepository : IServiceRepository { //Implementation of the Interface } I am would like to bind the repository above to class below while the class is

How inject depedency to CompositeControl using Ninject

ⅰ亾dé卋堺 提交于 2019-12-25 09:23:09
问题 How to inject dependency into CompositeControl? I tried the following approach - MyServerControl's Calculate is still null. Thanks! public class MyServerControl : CompositeControl { private TextBox TextBox1; private TextBox TextBox2; private Label Label1; [Inject] // **** This is null **** public ICalculate Calculate { get; set; } protected override void CreateChildControls() { TextBox1 = new TextBox {ID = "TextBox1", Text = "1"}; Controls.Add(TextBox1); TextBox2 = new TextBox {ID = "TextBox2

What did I get wrong, DI or Design, and how should I go about it?

北战南征 提交于 2019-12-25 07:58:52
问题 To make a long story short, the application that I am currently writing ought to impersonate the current logged in user. It's an application to manage information inquiries. Because of NHibernate.ISessionFactory not allowing more flexibility at the level of its connection string, I need to build the connection dynamically using the current user credentials. (By the way, I'm not complaining against NH, it's a wonderful that I use on each project.) So, I need to force authentication at start up