ninject

Setup Ninject for WCF [closed]

孤者浪人 提交于 2019-12-04 09:19:30
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Does anyone have a clear instruction on how to setup Ninject in WCF? been googling around but I cant see any updated guidelines on how to use Ninject in WCF. 回答1: Using NInject with WCF is the same as using any other DI container. To do this you need to use 3 WCF extensibility points: InstanceProvider ,

NHibernate throwing Session is closed

 ̄綄美尐妖づ 提交于 2019-12-04 09:04:10
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 user's name from a database table. I'm using Postgres as a database, and the ASP.NET Membership

Property Injection in Base Controller using Ninject 2

假装没事ソ 提交于 2019-12-04 08:52:38
I have the following code in my Global.aspx protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); RegisterAllControllersIn(Assembly.GetExecutingAssembly()); } protected override IKernel CreateKernel() { return new StandardKernel(new ServiceModule()); } I also have the following Ninject Module: internal class ServiceModule : NinjectModule { public override void Load() { Bind<IProductService>().To<ProductService>().InRequestScope(); } } I also have a base controller: public class BaseController : Controller { [Inject] public

How come there's no IKernel implementation in Ninject.Portable

老子叫甜甜 提交于 2019-12-04 08:41:06
I use and fancy Ninject alot. I wonder why there is no "BasicKernel" in Ninject.Portable? Is implementing IKernel require any call that PCLs don't contain? I'm talking about simple scenario (about: Bind<If1>().To<Class1>() and Get<If1>() )? The PCL version of Ninject is split into two libraries, Ninject.dll and Ninject.Common.dll as some of the code is platform-specific. Ninject cannot exist without its platform code. In order to use Ninject, you need to add the Portable.Ninject Nuget to both your portable library and to your main app/exe. Adding the package into the main app/exe is what

Dependency Injection in a 3 layer asp.net mvc application

家住魔仙堡 提交于 2019-12-04 08:14:38
问题 I have a 3 layer application and the layers are: Web: Presentation Layer (ASP.NET MVC) --> only sees BLL BLL: Business Logic Layer --> only sees DAL DAL: Data Access Layer So the Web layer doesn't know anything about my DAL layer. I have repository interfaces and concrete classes in my DAL , which are used in BLL layer in business logic classes. The question is, in order to decouple DAL and BLL , how do I setup Ninject to inject my repository implementations to the BLL layer? The same

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

≡放荡痞女 提交于 2019-12-04 08:13:06
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; set; } protected void Page_Load(object sender, EventArgs e) { var something = Repository.GetById(1);

Interception with Ninject. Fails to load IProxyRequestFactory

大憨熊 提交于 2019-12-04 08:00:58
I'm learning to use Ninject and Interceptor pattern. I have the following interceptor. public class MyInterceptor:IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Pre Execute: " + invocation.Request.Method.Name); foreach (var param in invocation.Request.Arguments) { Console.WriteLine("param : " + param); } invocation.Proceed(); Console.WriteLine("Post Execute: " + invocation.Request.Method.Name); Console.WriteLine("Returned: " + invocation.ReturnValue); } } And have a class named MyClass which got nothing but 2 simple methods, virtual to allow the interceptors

Making Ninject Interceptors work with async methods

半腔热情 提交于 2019-12-04 07:21:14
I am starting to work with ninject interceptors to wrap some of my async code with various behaviors and am having some trouble getting everything working. Here is an interceptor I am working with: public class MyInterceptor : IInterceptor { public async void Intercept(IInvocation invocation) { try { invocation.Proceed(); //check that method indeed returns Task await (Task) invocation.ReturnValue; RecordSuccess(); } catch (Exception) { RecordError(); invocation.ReturnValue = _defaultValue; throw; } } This appears to run properly in most normal cases. I am not sure if this will do what I expect

NamedLikeFactoryMethod in Ninject Extensions Factory working in non-compliance with documentation

限于喜欢 提交于 2019-12-04 06:41:20
问题 I have a small issue with my simple example. I have simple factory interface: public interface ICameraFactory { ICameraController GetNikonCamera(); ICameraController GetCanonCamera(); } I bind it as a factory: IKernel kernel = new StandardKernel(); kernel.Bind<ICameraFactory>().ToFactory(); When i try to convert: kernel.Bind<ICameraController>().To<NikonCameraController>() .Named("NikonCamera"); to: kernel.Bind<ICameraController>().To<NikonCameraController>() .NamedLikeFactoryMethod

How do you use method injection with Ninject?

左心房为你撑大大i 提交于 2019-12-04 05:41:48
I have a class which needs to use an IRepository for one method in it's class. Ideally, I would like to avoid having to resolve this dependency into the class's constructor, and so I found method level injection in Ninject and was wondering how this works? I understand how to set it up. What I'm confused about is how to call it? Example: class SomeClassThatUsesRepository { [Inject] public void QueryForSomeStuff(IRepository repository) { //do some stuff } } My problem is how do I call this method without specifying an IRepository? var someClass = Kernel.Resolve<SomeClassThatUsesRepository>();