ninject

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

吃可爱长大的小学妹 提交于 2019-12-23 10:28:46
问题 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

Replace Spring.Net IoC with another Container (e.g. Ninject)

蹲街弑〆低调 提交于 2019-12-23 10:10:23
问题 I'm curious to know if it's possible to replace Spring.Net's built-in IoC container with Ninject. We use Ninject on my team for IoC in our other projects so I would like to continue using that container if possible. Is this possible? Has anyone written a Ninject-Spring.Net Adapter?? Edit I like many parts of the Spring.Net package (the data access, transactions, etc.) but I don't really like the dependency injection container. I would like to replace that with Ninject Thanks 回答1: Jeffrey, can

Session is closed Object name: 'ISession'. at NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed() - How to stop the session from closing prematurely

一世执手 提交于 2019-12-23 09:32:41
问题 I am using NHibernate in an MVC C# application with MySQL. I am trying to have multiple users access the session. I have been using .InRequestScope() on my session but i am still getting: System.ObjectDisposedException: Session is closed! Object name: 'ISession'. at NHibernate.Impl.AbstractSessionImpl.ErrorIfClosed() * ...or DataReader errors when i have my colleagues all navigate to the same page that accesses a Service at the same time. My IMasterSessionSource injection Bind

NamedScope and garbage collection

[亡魂溺海] 提交于 2019-12-23 09:00:48
问题 (This question was first asked in the Ninject Google Group, but I see now that Stackoverflow seems to be more active.) I'm using the NamedScopeExtension to inject the same ViewModel into both the View and the Presenter. After the View have been released, memory profiling shows that the ViewModel is still retained by the Ninject cache. How can I make Ninject release the ViewModel? All ViewModels are released when the Form is Closed and Disposed, but I'm creating and deleting Controls using a

MVC3 + Ninject: What is the proper way to inject the User IPrincipal?

南楼画角 提交于 2019-12-23 07:55:40
问题 I have seen the following two example for injecting the User IPrincipal: Method 1: kernel.Bind<IPrincipal>() .ToMethod(context => context.Kernel.Get<RequestContext>().HttpContext.User) .InRequestScope(); Method 2: kernel.Bind<IPrincipal>() .ToMethod(context => HttpContext.Current.User) .InRequestScope(); Is there any difference in the two? Is one preferred? 回答1: The two methods are identical. Both are going to return the HttpContext obect for the current HTTP Request. 来源: https:/

Ninject: Injecting two different objects of same type

元气小坏坏 提交于 2019-12-23 07:47:24
问题 If I have a class, which has dual dependencies on the same type (needs two different instances), if the only difference between the instances is a deeper dependency, what's the best way to have Ninject perform DI and keep the two graphs separate? Example object graph: foo → ClassA → ClassB bar → ClassA → ClassB Class C 's constructor: public class C { public C(ClassB foo, ClassB bar) { … } } So how do I make sure that the ClassB instantiated with foo gets supplied as the ClassB dependancy foo

Ninject bind all classes implementing the same interface

孤者浪人 提交于 2019-12-23 06:58:39
问题 I have an interface class: public interface IStartUpTask { bool IsEnabled { get; } void Configure(); } I have multimple classes implementing the same interface One of the classes looks like this: public class Log4NetStartUpTask : IStartUpTask { public bool IsEnabled { get { return true; } } public void Configure() { string log4netConfigFilePath = ConfigurationManager.AppSettings["log4netConfigFilePath"]; if (log4netConfigFilePath == null) throw new Exception("log4netConfigFilePath

Custom Validation for Duplicate UserName in DB

无人久伴 提交于 2019-12-23 05:39:29
问题 If you have better approach to handle custom Validation please let me know. I don't want service layer for this please. Read below 5th option what I want. I have 1 - IUserRepository -> bool IsUserRegistered(string userName); 2 - UserRepository with Method readonly EFDBContainer _db = new EFDBContainer(); public bool IsUserRegistered(string userName) { return _db.Users.Any(d => d.UserName == userName); } 3 - Ninject --> UserController is DI public static void RegisterServices(IKernel kernel) {

Dependency injection into referenced project

我怕爱的太早我们不能终老 提交于 2019-12-23 05:16:33
问题 I've been trying to achieve something with Ninject (without a great understanding of the library) and have realized it may not be possible to do what I want. I've got one of our own projects that I've referenced, and was attempting to use Ninject to push some dependencies in, something like: public class ImageHelper { [Inject] public static AdaptiveImageSettings Settings { get; set; } [Inject] public static IImageSizerFactory Factory { get; set; } } } The aim is to have some settings (which

Setting the connection string of a DBContext in my repository class using Ninject

夙愿已清 提交于 2019-12-23 05:13:07
问题 I have an MVC 5 application that uses EF 6 and implements Repository pattern with dependency injection using the DI container Ninject. The connection string for the dbcontext is stored in the Web.config file which the EF Context properly finds. Everything works fine. Lately, I have a requirement that the connection to my DBContext need to be determined at runtime and connect to different databases (but with exactly the same structure). So, I need to change the sql connectionstring part from