ninject-2

Inject repository to custom membership provider with Ninject

佐手、 提交于 2019-12-17 07:33:07
问题 I'm trying to inject a repository to a custom membership provider with ninject in MVC 3. In MembershipProvider I have tried the following: [Inject] public ICustomerRepository _customerRepository{ get; set; } And [Inject] public TUMembershipProvider(ICustomerRepository customerRepository) { _customerRepository = customerRepository; } In my ninject module i tried the following: Bind<MembershipProvider>().ToConstant(Membership.Provider); None of the above works. When i use(in global.asa) kernel

Dependency Inject with Ninject 2.0

天涯浪子 提交于 2019-12-14 02:47:43
问题 A little question regarding Ninject. I use a WCF 'duplex channel' to communicate with a service. The channel is defined as an interface, lets call it IMyChannel for simplicity. To instantiate a channel we use DuplexChannelFactory<IMyChannel> object's CreateChannel() method. So far I have manage to bind the factory class with this. Bind< DuplexChannelFactory< IMyChannel>>().ToMethod(context => new DuplexChannelFactory< IMyChannel>( new MessageEndPoint(), new NetTcpBinding(), "net.tcp:/

Using WithConstructorArgument and creating bound type

笑着哭i 提交于 2019-12-13 06:21:35
问题 I have a binding that looks like this: kernel.Bind<IRepository<Holiday>>().To<RepositoryBase<Holiday>>(); The problem is that RepositoryBase takes a contructor paramter of UnitOfWork called context. This is not, in and of itself a problem. Ninject should resolve it. Except for the fact that I have two UnitOfWork implementations, both bound using an attribute discriminator. kernel.Bind<IUnitOfWork>().To<MS_DevEntities>().WhenTargetHas<MsDataAttribute>() .InRequestScope(); How can specify that

Understanding Ninject with a more complex scenario

扶醉桌前 提交于 2019-12-13 02:43:56
问题 I am trying to use ninject to.. well do what ninject does.. Basically the injection isnt happening. In my code below I am creating the Kernel in my "test" and expecting an IDrinkCan implementation to somehow get into my CokeComsumer class. I think i have missed something here.. since the IDrinkCan is null when I put a break point on the CokeConsumer constructor. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ninject; using Ninject.Modules; using

Dependency Injection: How to configure interface bindings for wrapping

三世轮回 提交于 2019-12-12 10:58:43
问题 So, let's say I have an interface IThingFactory : public interface IThingFactory { Thing GetThing(int thingId); } Now, let's say I have a concrete implementation that retrieves Thing s from a database. Now, let's also say I have a concrete implementation that wraps an existing IThingFactory and checks for a Thing 's presence in, say, an in-memory cache before hitting the wrapped IThingFactory . Something like: public class CachedThingFactory : IThingFactory { private IThingFactory _wrapped;

How to use Ninject to inject services into an authorization filter?

情到浓时终转凉″ 提交于 2019-12-12 08:46:42
问题 I am using asp.net mvc 3, ninject 2.0 and the ninject mvc 3 plugin. I am wondering how do I get service layers into my filter(in this case an authorization filter?). I like to do constructor inject so is this possible or do I have to property inject? Thanks Edit I have this for property inject but my property is always null [Inject] public IAccountService AccountServiceHelper { get; set; } protected override bool AuthorizeCore(HttpContextBase httpContext) { // check if context is set if

How to wrap lazy loading in a transaction?

左心房为你撑大大i 提交于 2019-12-11 08:03:26
问题 I am using nhibernate and the nhibernate profile what keeps throwing this alert. Use of implicit transactions is discouraged" I actually wrap everything in a transaction through ninject public class NhibernateModule : NinjectModule { public override void Load() { Bind<ISessionFactory>().ToProvider<NhibernateSessionFactoryProvider>().InSingletonScope(); Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession()).InRequestScope() .OnActivation(StartTransaction)

Ninject basics with example please

流过昼夜 提交于 2019-12-10 20:37:10
问题 Scenario: Quite new to DI and Ninject but would love to master it so that I know what'm doing and why. While going through few examples and documentation I noticed the following: 1. ToConstructor. 2. ToMethod 3. Self If someone could help me to understand when and how above can be used, will be good. An example will be good. Thanks. 回答1: Hy, Self bindings declare a binding of a certain type to itself. Self bindings are not needed for types which have a parameterless constructor. Ninject can

Model.IsValid always returning true

﹥>﹥吖頭↗ 提交于 2019-12-10 17:45:10
问题 Ok I am near wits end here. I've got a simple MVC3 application with a viewmodel ViewModel public class TicketViewModel { public Ticket Ticket { get; set; } [DisplayName("Name")] [Required(ErrorMessage = "Requestor's name is required.")] public string Name { get; set; } } Controller [HttpPost] public ActionResult Create(TicketViewModel vm) { if(ModelState.IsValid) { TempData["message"] = "Your ticket has been submitted."; TempData["message-class"] = "success"; return RedirectToAction("Index");

How to keep IoC container in one place, while inner classes need to create dependencies after beeing constructed

耗尽温柔 提交于 2019-12-10 14:44:06
问题 I started to use Ninject , on this relatively small project and i have run into a problem: i have this class class SomeService : ISomeService that depends on class BizLogicModule : IBizLogicModule that in turn depends on class DataRepository : IDataRepository the DataRepository has a ctor that looks like: DataRepository(BizEntityModel context) Now, i need to be able to use a single instance of BizEntityModel across more than one IDataRepository instance. I also need to create IDataRepository