ninject

Inject Entity Framework DbContext using Ninject in ASP.NET MVC5

≡放荡痞女 提交于 2019-12-24 01:24:32
问题 I have just landed in dependency injection world. I have the following custom DbContext- public partial class SkyTrackerContext: DbContext { public SkyTrackerContext(): base() { Database.SetInitializer(new SkyTrackerDBInitializer()); } } Would like inject SkyTrackerContext in this base controller- public abstract class BaseController : Controller { public BaseController() {} [Inject] public SkyTrackerContext MyDbContext { get; set; } } Sample usage- public class LoginController :

Configuring Ninject

亡梦爱人 提交于 2019-12-24 00:59:47
问题 Following a discussion with Remo Gloor (main dev) about our Ninject configuration, .NET memory profiling / risks for leaks / Ninject / Direct delegate roots, I'd like to get some clarity on configuring it properly for an ASP.NET webforms application. We have a requirement currently where we are doing the following: Bind<ISearchService>() .ToMethod(ctx => new BaseSearchService(ctx.Kernel.GetDefault<IDataRetrievalService>())) .InSingletonScope() .Named("BaseSearchService"); Bind<ISearchService>

Ninject: One interceptor instance per one class instance being intercepted?

陌路散爱 提交于 2019-12-24 00:16:57
问题 I'm currently having a problem, trying to wire up exactly one interceptor instance per one instance of class being intercepted. I'm creating and Advice in the InterceptorRegistrationStrategy and setting the callback to resolve an interceptor from the kernel (it has an injection constructor). Please note that I can only instantiate interceptor in the callback because InterceptorRegistrationStrategy does not have reference to Kernel itself. IAdvice advice = this.AdviceFactory.Create(methodInfo)

Ninject: Error activating string

五迷三道 提交于 2019-12-23 20:21:09
问题 Im following a guide of how to setup SQLite. In the guide he uses code-behind like this: public MainPage() { InitializeComponent(); // Setup database var path = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "test.sqlite")); _connection = new SQLiteConnection(new SQLitePlatformWP8(), path); } Im trying to do the same thing but instead by following MVVM. I thought his would be the way to go: public override void Load() { var path = Path.Combine(Path.Combine(ApplicationData

Ninject Garbage Collection [closed]

笑着哭i 提交于 2019-12-23 18:50:27
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 8 years ago . I am using Ninject in a n-tier application consisting of services, repositories, all wired up with the UnitOfWork pattern and Ninject. Further, I have

Generic Interface dependency injection into factory

徘徊边缘 提交于 2019-12-23 17:45:52
问题 I'm playing around with DI and Ninject. I'm open for suggestions on how to solve this in another way. I'm trying to make sure the concrete implementations of ICreateOrders can be replaced - if need be. Maybe there's another way or pattern? Solutions like this: C# - Ninject, IoC and factory pattern are fine but I was hoping to inject the possible creators into the factory and making the factory pick one based on OrderRequest. This doesn't work. kernel.Bind(typeof(ICreateOrders<,>)).To(typeof

Constructor Argument Enums and Magic Strings

隐身守侯 提交于 2019-12-23 17:27:48
问题 I am working on my c# .net application and use implement IoC/DI pattern using Ninject, Now Ninject has a class named ConstructorArgument which takes two arguments(argName,argValue). So i need to pass static argName something like this new ConstructorArgument("strVar","") passing hardcoded string does not seems like a good option. So i want to create something like dynamics enums using reflection for the constructor arguments, so i dont need to pass hardcoded strings. Please guide me through

Cannot upgrade Ninject to latest version in Nuget

ε祈祈猫儿з 提交于 2019-12-23 13:03:56
问题 I have a ASP.NET WebForms application that uses some Ninject packages, but I am stuck at a certain version. When I try to upgrade to the latest version, I get "Unable to resolve dependencies" issues. The packages in question are: Package InstalledVer LatestVer ------------------------------------------------------ Ninject v3.2.2 v3.3.4 Ninject.Web v3.2.1 ✔ v3.2.1 Ninject.Web.Common v3.2.3 v3.3.1 Ninject.Web.Common.WebHost v3.2.3 v3.3.1 If I try updating Ninject , I get: Unable to resolve

Ninject: give the parent instance to a child being resolved

旧城冷巷雨未停 提交于 2019-12-23 13:03:21
问题 I have this class hierarchy: public interface ISR { } public interface ICU { } public interface IFI { } public class CU : ICU { } public class SR : ISR { public SR(IFI fi) { FI = fi; } public IFI FI { get; set; } } public class FI : IFI { public FI(ISR sr, ICU cu) { SR = sr; CU = cu; } public ISR SR { get; set; } public ICU CU { get; set; } } public class Module : NinjectModule { public override void Load() { Bind<ISR>().To<SR>(); Bind<ICU>().To<CU>(); Bind<IFI>().To<FI>(); } } class Program

ASP.NET MVC 2, Ninject 2.2 and no parameterless constructor defined for this object

风格不统一 提交于 2019-12-23 10:29:32
问题 So I've been spending some time with ASP.NET MVC 2 (currently stuck with using Visual Studio 2008) and have now moved onto using Ninject 2.2 and its MVC integration. I've downloaded Ninject 2.2 and Ninject.Web.Mvc from the following locations: https://github.com/downloads/ninject/ninject/Ninject-2.2.0.0-release-net-3.5.zip https://github.com/downloads/ninject/ninject.web.mvc/Ninject.Web.Mvc2-2.2.0.0-release-net-3.5.zip And referenced them in my MVC 2 project. My Global.asax.cs file looks like