ninject

Ninject Scope and System.Threading.Timer

别来无恙 提交于 2019-12-24 18:41:05
问题 How to invoke a new Ninject context on a Timer task? Having a hard time configuring ninject scope to unitofwork. If I set as InRequestScope() it doesn't work on non request tasks. So I set up like below so that I can get InThreadScope for tasks: kernel.Bind<IUnitOfWork>().To<myEntities>().InScope(ctx => HttpContext.Current ?? StandardScopeCallbacks.Thread(ctx)); But that way, when I set up a timer Timer timer = new Timer(_ => DelayedDisconnect(chatUser.User.AuthorizationId), null, TimeSpan

Ninject 3 multiple bindings

旧时模样 提交于 2019-12-24 17:25:44
问题 My question is really a repeat of an old question posted here: Ninject 2.2 multiple bindings It seems someone was going to deal with this back in 2011. Does anyone know if there is some way to turn off such warnings in Ninject? Or some other workaround? EDIT In response to @BatteryBackupUnit, here is my exact problem: I have multiple libraries... and in my core library, I do something like this: Find all assemblies referenced by the host application (including the host) Find all types

How do you add a runtime string parameter into a dependency resolution chain?

泄露秘密 提交于 2019-12-24 16:20:35
问题 How could I setup my chosen DI for this kind of setup: public abstract class BaseRepo { public BaseRepo(string token) { } } public RepoA : BaseRepo, IRepoA { // implementation of interface here } public ViewModelA { IRepoA _repo; public ViewModelA(IRepoA repo) { this._repo = repo; } public DoMethod() { this._repo.DoSomeStuff(); } } In real scenario, the token parameter on the base class is resolved after the user has been logged in. I was thinking of just configuring the interfaces for DI

How to pass parameters to a transient object created by Ninject?

自闭症网瘾萝莉.ら 提交于 2019-12-24 15:31:51
问题 I'm developing an ASP.NET MVC 3 project using NInject to create object instances. It builds an object graph for each Action. It works well in most cases. However, I have a new requirement that I must pass some parameters (from request) to a few objects (which are transient) in the object graph. How can I do that? Here is an example: class MyController : Controller { [Inject] public IProcess Process {get;set;} public ActionResult MyAction(int value) { // how to pass the 'value' to an object

Dependency Injection with Ninject and Global Filter: IAuthorizationFilter

杀马特。学长 韩版系。学妹 提交于 2019-12-24 14:58:19
问题 I use standart NinjectMVC3 Bootstrapper installed in the App_Start folder. My application class looks like: public class MvcApplication : HttpApplication { static void RegisterRoutes(RouteCollection routes) { // ... routes here ... } public void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } static void RegisterGlobalFilters(GlobalFilterCollection filters) { // empty } } I have only following

Using NHibernate interceptor together with Ninject to retrieve the logged in user

谁说我不能喝 提交于 2019-12-24 13:33:40
问题 I was reading this article and found it quite interesting (thanks @Aaronaught). Was what came closest to solve my problem. The only detail is that in my case I would use the NHibernate interceptor, but an exception is thrown An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll Code Session factory: public class SessionFactoryBuilder : IProvider { private ISessionFactory _sessionFactory; private readonly Configuration _configuration; public

Using Ninject to inject dependencies into externally constructed objects (user control)

◇◆丶佛笑我妖孽 提交于 2019-12-24 13:32:24
问题 I would like to use Ninject in my WinForms application. I cannot figure out how to use it for my user controls. Sometimes they rely on the services I want to configure through the DI framework. These controls need to be manageable through the designer (thus need default constructors). So, is there a way to inject dependencies into properties of this user control? Since the designer needs to be able to construct it, kernel.Get<TestClass> won't work here. Is there a method or some code that

How to bind a string to a method of an object when it is injected into another?

会有一股神秘感。 提交于 2019-12-24 13:29:43
问题 I have a NHibernate.Cfg.Configuration provider. ConfigurationProvider public class ConfigurationProvider : Provider<Configuration> { public class ConfigurationProvider(string connectionString , Assembly mappings) { ConnectionString = connectionString; Mappings = mappings; } protected override Configuration CreateInstance(IContext context) { var c = new Configuration().Configure(); c.AddAssembly(Mappings); c.Properties["connection.connection_string"] = ConnectionString; return c; } private

Error using Ninject with ASP.NET V4

做~自己de王妃 提交于 2019-12-24 12:17:54
问题 I'm trying to learn about Dependency Injection in ASP.NET MVC4 using this guide: http://www.codeproject.com/Articles/412383/Dependency-Injection-in-asp-net-mvc4-and-webapi-us However I am getting the following exception being thrown when I try and run the application: An exception of type 'System.IO.FileNotFoundException' occurred in Ninject.dll but was not handled in user code Additional information: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral,

How to load records from Setting table of NopCommerce v3.5

China☆狼群 提交于 2019-12-24 11:56:24
问题 I'm trying to use NopCommerce v3.5 and trying to replace Autofac with Ninject v3.2. I've been searching how NopCommerce load records from Setting table, it's still not clear. And if ever, I want to load the settings using Ninject. Thank you for any help. Here's a sample code in Nop.web.Framework.DependencyRegistrar.cs builder.RegisterType<SettingService>().As<ISettingService>() .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static")) .InstancePerLifetimeScope(); builder