ninject-2

Ninject WithConstructorArgument : No matching bindings are available, and the type is not self-bindable

时光总嘲笑我的痴心妄想 提交于 2019-12-03 09:51:56
My understanding of WithConstructorArgument is probably erroneous, because the following is not working: I have a service, lets call it MyService, whose constructor is taking multiple objects, and a string parameter called testEmail. For this string parameter, I added the following Ninject binding: string testEmail = "test@example.com"; kernel.Bind<IMyService>().To<MyService>().WithConstructorArgument("testEmail", testEmail); However, when executing the following line of code, I get an exception: var myService = kernel.Get<MyService>(); Here is the exception I get: Error activating string No

ASP.NET MVC 3 and Global Filter Injection

大憨熊 提交于 2019-12-03 08:41:23
Hello am an trying to implement a global filter with injection. The filter looks like this. public class WikiFilter : IActionFilter { private IWikiService service; public WikiFilter(IWikiService service) { this.service = service; } public void OnActionExecuting(ActionExecutingContext filterContext) { !!!Code here!! } public void OnActionExecuted(ActionExecutedContext filterContext) { throw new NotImplementedException(); } } And i have attached the filter with injection the following way in my global.asax. public class MvcApplication : System.Web.HttpApplication, IAuthenticationApplication<User

Ninject, Bind should be .InRequestScope() OR .InSingletonScope()

妖精的绣舞 提交于 2019-12-03 07:07:50
I have Below code One is bindable to my User Repository and another for Cache. What scope should I use for UserRepository and Cache. Should Scope on UserRepository be Singleton? this.Bind<IUserRepository>().To<UserRepositary>().InRequestScope(); this.Bind<IDistributedCacheService>().To<DistributedCacheService>().InSingletonScope(); Usually the repositories are bound inrequestscope because that generally defines the unit of work or database transaction size. Update: Here is a bit more information on managing critical resources using ninject. I ran into this while binding my repos inrequestscope

Ninject: How to bind an open generic with more than one type argument?

馋奶兔 提交于 2019-12-03 06:45:59
问题 I'm using Ninject 2.2, and I'm trying to setup a binding for an open generic that takes two type arguments. According to this answer by qes, the correct syntax to bind IRepository<T> to Repository<T> is this: Bind(typeof(IRepository<>)).To(typeof(Repository<>)); The above syntax works perfectly if IRepository takes just one type argument, but breaks if it takes more (gives a Using the generic type 'Repository<T,U>' requires 2 type arguments compile time error.) How can I bind IRepository<T,U>

MVC 3: How to learn how to test with NUnit, Ninject, and Moq?

好久不见. 提交于 2019-12-03 00:14:23
问题 Short version of my questions: Can anyone point me toward some good, detailed sources from which I can learn how to implement testing in my MVC 3 application, using NUnit, Ninject 2, and Moq? Can anyone here help clarify for me how Controller-Repository decoupling, mocking, and dependency injection work together? Longer version of my questions: What I'm trying to do ... I am currently beginning to create an MVC 3 application, which will use Entity Framework 4, with a database first approach.

Ninject: How to bind an open generic with more than one type argument?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 21:18:56
I'm using Ninject 2.2, and I'm trying to setup a binding for an open generic that takes two type arguments. According to this answer by qes, the correct syntax to bind IRepository<T> to Repository<T> is this: Bind(typeof(IRepository<>)).To(typeof(Repository<>)); The above syntax works perfectly if IRepository takes just one type argument, but breaks if it takes more (gives a Using the generic type 'Repository<T,U>' requires 2 type arguments compile time error.) How can I bind IRepository<T,U> to Repository<T,U> ? Thanks. Bind(typeof(IRepository<,>)).To(typeof(Repository<,>)); Try that.... 来源:

ASP.Net MVC 3, Ninject and Quartz.Net - How to?

江枫思渺然 提交于 2019-12-02 17:18:27
I am now using Ninject 2.2.1.4, with my MVC3, i'm success to config Ninject run with it, but i don't know how to make Ninject run with Quartz.Net in my MVC3 Can anyone help? Create a JobFactory that uses Ninject public class NinjectJobFactory : IJobFactory { private readonly Func<Type, IJob> jobFactory; public NinjectJobFactory (Func<Type, IJob> jobFactory) { this.jobFactory = jobFactory; } public IJob NewJob(TriggerFiredBundle bundle) { return this.jobFactory(bundle.JobDetail.JobType); } } and a QuarzSchedulerProvider public class QuartzSchedulerProvider : Provider<IScheduler> { private

MVC 3: How to learn how to test with NUnit, Ninject, and Moq?

£可爱£侵袭症+ 提交于 2019-12-02 13:57:47
Short version of my questions: Can anyone point me toward some good, detailed sources from which I can learn how to implement testing in my MVC 3 application, using NUnit, Ninject 2, and Moq? Can anyone here help clarify for me how Controller-Repository decoupling, mocking, and dependency injection work together? Longer version of my questions: What I'm trying to do ... I am currently beginning to create an MVC 3 application, which will use Entity Framework 4, with a database first approach. I want to do this right, so I am trying to design the classes, layers, etc., to be highly testable. But

Inject attribute doesn't work for field

点点圈 提交于 2019-12-02 02:26:10
问题 Inject attribute is not working for field. [Inject] public MyContext context; //Not injected [Inject] public MyContext context {get; set;} //Injected I am using default Ninject settings. Why field is not injected ? 回答1: Because it is not allowed. From the Ninject 2 Beta announcement: Things that were in Ninject 1.x that are not in Ninject 2: Field injection: Ninject 2’s injection is now driven by expression trees, and in .NET 3.5 there is no way to set field values with an expression tree.

Inject attribute doesn't work for field

≡放荡痞女 提交于 2019-12-01 20:38:29
Inject attribute is not working for field. [Inject] public MyContext context; //Not injected [Inject] public MyContext context {get; set;} //Injected I am using default Ninject settings. Why field is not injected ? Because it is not allowed. From the Ninject 2 Beta announcement : Things that were in Ninject 1.x that are not in Ninject 2: Field injection: Ninject 2’s injection is now driven by expression trees, and in .NET 3.5 there is no way to set field values with an expression tree. Since this is a bad practice anyway, I decided to cut it. 来源: https://stackoverflow.com/questions/5532812