ninject

Ninject in ASP.NET MVC4

人走茶凉 提交于 2020-01-01 01:58:31
问题 So after much screwing around I finally got Ninject wired in and compiling in my MVC4 application. The problem I was running into is the IDependencyScope interface no longer exists from what I can tell and the System.Web.Http.Dependencies namespace was done away with. So, my problem now is I have everything wired in and upon running the application I get: Sequence contains no elements [InvalidOperationException: Sequence contains no elements] System.Linq.Enumerable.Single(IEnumerable`1 source

Ninject.MVC3, Nuget, WebActivator oh my

 ̄綄美尐妖づ 提交于 2019-12-31 09:46:02
问题 I want to setup Ninject to do a simple test, as well as demonstrate the ease-of-setup using Nuget. I want to resolve a sample service. public interface ITestService { string GetMessage(); } public class TestService : ITestService { public string GetMessage() { return "hello world"; } } I run the NuGet Install-Package NinjectMVC3 .... it nicely drops NinjectMVC3.cs into my App_Start folder, decorated with some WebActivator attributes to get it all loaded. Next I add my binding in the

How to inject ModelState as parameter with Ninject?

余生颓废 提交于 2019-12-31 03:26:10
问题 Im very new to Ninject. I want to find a way to pass Modelstate of a controller further to service layer. what i have right now: private readonly IAccountService service; public AccountController(ILanguageService ls, ISessionHelper sh) { this.service = new AccountService(new ModelStateWrapper(this.ModelState)); this.languageService = ls; this.sessionHelper = sh; } public AccountService(IValidationDictionary validationDictionary) { this.validationDictionary = validationDictionary; } want i

Cannot get Ninject.Extensions.Conventions to work

时间秒杀一切 提交于 2019-12-31 02:01:09
问题 I've been trying to get Ninject.Extensions.Conventions for (Ninject 3+) working, with no luck. I boiled it down to a found sample console app, and I can't even get that going. Here's what I have: class Program { static void Main(string[] args) { var kernel = new StandardKernel(); kernel.Bind(x => x .FromThisAssembly() .SelectAllClasses() .BindAllInterfaces()); var output = kernel.Get<IConsoleOutput>(); output.HelloWorld(); var service = kernel.Get<Service>(); service.OutputToConsole();

Ninject UserManager and UserStore

旧城冷巷雨未停 提交于 2019-12-30 10:58:09
问题 What is the most elegant way to inject UserManager and UserStore into a controller using ninject? For example, the context can be injected like this: kernel.Bind<EmployeeContext>().ToSelf().InRequestScope(); public class EmployeeController : Controller { private EmployeeContext _context; public EmployeeController(EmployeeContext context) { _context = context; } Can ninject inject UserManager and UserStore with a one line of code into a controller?! If not, what is the easiest way? I don't

Ninject and XML configuration Binding

这一生的挚爱 提交于 2019-12-30 09:30:05
问题 i have been searching the internet for any sample or getting start article on how to do binding with Ninject using XML extension but i couldnt find any help ! , can any body provide me with a very small sample on how can i do that ? thanks in advance 回答1: I can't find any examples either, but honestly the source code is very small - I would just download (here) and read through the test cases. The unit test project has some examples, like this: <module name="basicTest"> <bind name="melee"

Ninject.MVC3 Bootstrapper's Kernel property is marked as Obsolete. How can I get access to the kernel?

旧时模样 提交于 2019-12-30 08:22:35
问题 I updated Ninject.MVC3 package from 2.2.1.0 to 2.2.2.0. Before I had access to the Kernel object through BootStrapper.Kernel property but in the new version Kernel property is marked as obsolete. I get a warning saying 'Public ReadOnly Property Kernel As Ninject.IKernel' is obsolete: 'Do not use Ninject as Service Locator'. Is there a different way to access the kernel in the new version? 回答1: The reason why this has been marked Obsolete and will be changed to internal in future is that

What is the best practice for WinForms dialogs with ninject? [closed]

你。 提交于 2019-12-30 07:29:06
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . I try to create aplication with Ninject. I have one MainForm and dialog form for settings. How should i implement this? Should MainForm have a Kernel instance and then create SettingsForm with Get<SettingsForm>() method? Or should MainForm constructor have parameter with

Ninject - dynamically specifying a connection string based on a sub domain

最后都变了- 提交于 2019-12-30 07:16:22
问题 I'm trying to specify a connection string dynamically based of the url using ninject. I'm using the ninject.mvc nuget package that uses the webActivator. My code is as follows: my injection: kernel.Bind<IUnitOfWork>().To<UnitOfWork>() .WithConstructorArgument("connectionString", MvcApplication.GetConnectionStringName()); my global.asax private static HttpContext _context; public static string GetConnectionStringName() { var subDomain = String.Empty; if (_context != null) { subDomain =

Null reference in web api call

China☆狼群 提交于 2019-12-30 06:59:09
问题 This is a weird one, and I'm at a loss to understand what's going on here. I have a web api project that in one controller a call to a certain method eventually calls a function in a service that looks like this: public MyClassBase GetThing(Guid id) { if (cache.ContainsKey(id)) { return cache[id]; } else { var type = typeof(MyClassBase).Assembly.GetTypes().FirstOrDefault ( t => t.IsClass && t.Namespace == typeof(MyClassBase).Namespace + ".Foo" && t.IsSubclassOf(typeof(MyClassBase)) && (t