ninject

NHibernate throwing Session is closed

冷暖自知 提交于 2020-01-01 12:22:14
问题 I'm flapping in the wind, so I thought I'd ask here... Please let me know if this is obvious and has been answered before. I'm building an MVC 3 site which works fine while I'm running it with one user, where I click through the pages. However, if I madly hit refresh, eventually I hit a "Session is closed". I've isolated out almost all of all my repository to try to get to the bottom, so I know have it erroring on the homepage. The only thing that is being called in the repository is get the

Ninject Contextual Binding at RunTime

。_饼干妹妹 提交于 2020-01-01 11:48:17
问题 I am trying to understand Ninject Contextual Binding. I understand the scenarios where I know my context at design time. e.g. I understand that I can use Named Attributes to Bind the DB object to a mock DB when I want to use it in a test class and to a SQL DB when I use it from my actual code. However, I don't know how to handle contextual Binding at runtime. e.g. let's say I am writing software for a shopping center. The shopkeeper can use a keyboad for billing or a barcode scanner. I don't

Ninject.Web.PageBase still resulting in null reference to injected dependency

拟墨画扇 提交于 2020-01-01 10:44:50
问题 I have an ASP.NET 3.5 WebForms application using Ninject 2.0. However, attempting to use the Ninject.Web extension to provide injection into System.Web.UI.Page, I'm getting a null reference to my injected dependency even though if I switch to using a service locator to provide the reference (using Ninject), there's no issue. My configuration (dumbed down for simplicity): public partial class Default : PageBase // which is Ninject.Web.PageBase { [Inject] public IClubRepository Repository { get

In Ninject, how can I run custom code on an object after it is created with Bind<..>.ToSelf()?

雨燕双飞 提交于 2020-01-01 10:01:17
问题 In Ninject's dependency injection, if you set up a binding of a class to itself like so: Bind<SomeClass>().ToSelf(); Ninject very nicely resolves any dependencies SomeClass has and gives you the object back. I want to be able to do something to the SomeClass it returns every time it creates a new one, so like a post-processing event. I could use the .ToMethod (or ToFactoryMethod) binding to explicitly new it up, but I would like all its dependencies resolved by Ninject beforehand. It wouldu

NHibernate, dependency injection. Close ISession properly

我的梦境 提交于 2020-01-01 06:55:14
问题 I am using Ninject, NHibernate, ASP.NET MVC3 and repository pattern. The module binding in Ninject is as following. Bind<ISessionFactory>().ToProvider(new SessionFactoryProvider()).InSingletonScope(); Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession()).InRequestScope(); The question is should the repository take an ISession or ISessionFactory. If it takes an ISessionFactory then in the repository I can open a session when necessary and close it after use.

ASP.NET Identity 2 Invalidate Identity Difficulties

为君一笑 提交于 2020-01-01 06:45:06
问题 I have been updating my implementation of ASP.NET Identity all day today and I feel I'm on the last step, but just can't make it work. All I want to happen is to have the user's current session (if any) invalidated when something about them changes and to send them back to the login page. From the dozens of Identity related articles I've been reading today, I've settled that I have to override the OnValidateIdentity delegate, but it's just not working. Below is my code, I would really

Can I use my Ninject .NET project within Orchard CMS?

為{幸葍}努か 提交于 2020-01-01 03:22:05
问题 I am creating a website using Orchard CMS and I have an external .NET project written with Ninject for dependency injection which I would like to use together with a module within Orchard CMS. I know that Orchard uses Autofac for dependency injection and this is causing me problems since I never worked with DI before. I have created an Autofac module, UserModule , which registers the a source, UserRegistrationSource , like this: UserModule.cs public class UserModule : Module { protected

Ninject with ASP.Net webforms and MVC

人盡茶涼 提交于 2020-01-01 03:13:08
问题 I want to use Ninject in a project which combines ASP.Net webforms and ASP.Net MVC. I'm using Ninject 2, but when I use NinjectHttpApplication from Ninject.Web.Mvc it complains when I use somethings like a PageBase that the Kernel is not created. I have the following in the Global.asax and am unsure what to add. public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication { protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable

Ninject and ASP.NET Web API

亡梦爱人 提交于 2020-01-01 02:32:11
问题 Before I set up the question you should know that I got my current code from this page: http://www.strathweb.com/2012/05/using-ninject-with-the-latest-asp-net-web-api-source/ I'm trying to use ASP.NET Web API and Ninject in my application by using an IDependencyResolver adapter found on the site above. I created all the code just like it shows on the site and it works but when I load up my appication my regular controllers fail and show this error: [MissingMethodException: No parameterless

Dependency Injection and development productivity

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 02:29:18
问题 Abstract For the past few months I have been programming a light weight, C# based game engine with API abstraction and entity/component/scripting system. The whole idea of it is to ease the game development process in XNA, SlimDX and such, by providing architecture similar to that of the Unity engine. Design challenges As most game developers know, there are a lot of different services you need to access throughout your code. Many developers resort to using global static instances of e.g. a