Options For Wiring Dependencies With NInject?
Jan 27, 2010
With NInject (preferably 2.0), what options do we have wrt wiring up our object dependencies in a web application?
Can they be defined in an XML configuration file?
Or does it have to be done via code?
View 4 Replies
Similar Messages:
Jan 18, 2011
I have a Default.aspx program that contains a Treeview with a SiteMapDataSource. I also have a web.sitemap loaded up with urls. When I run the deafult app I get the tree layout that matches the numbers of options but no text on any of the options to click.
View 1 Replies
Apr 1, 2010
In my Asp.Net project I wanna use Property Auto-wiring, e.g. for my ILogger. Basically I placed it as Property into class where I need to use it. Like below.
[code]....
Update:
- I didnt mentioned before, but its Asp.Net webforms 3.5.
- I can't see what I am missing. I guess it could be because the injection gets involved later in process and didnt get set in requested class.
View 2 Replies
Jun 1, 2010
I am trying to use LinkButtons with the DefaultButton property of the ASP.NET Panel in an UpdatePanel. I have read and used the various other answers that are around describing the wiring up of the click event so that a full postback is not done instead of a partial postback. When the page loads, I wire up the .click function of the LinkButton so that the DefaultButton property of the ASP.NET panel will work.
This all works fine, until you bring an UpdatePanel into the mix. With an UpdatePanel, if there is a partial postback, the script to wire up the .click function is not called in the partial postback, and hitting enter reverts to causing a full submit of the form rather than triggering the LinkButton.
How can I cause javascript to be executed after a partial postback to re-wire up the .click function of the LinkButton? I have produced a sample page which shows the problem. There are two alerts showing 1) When the code to hook up the .click function is being called, and 2) When the .click function has been called (this only happens when you hit enter in the textbox after the event has been wired up). To test this code, type something in the textbox and hit Enter. The text will be copied to the label control, but "Wiring up Event Click" alert will not be shown. Add another letter, hit enter again, and you'll get a full postback without the text being copied to the label control (as the LinkButton wasn't called). Because that was a full postback, the Wiring Up Event Click event will be called again, and the form will work properly the next time again.
This is being done with ASP.NET 3.5.
Test Case Code:
[Code].....
View 1 Replies
Mar 14, 2011
For a "dashboard" module I need to dynamically load user controls based on criteria as the user enters the page (role, etc). The problem is that the events are not being fired at all from the controls
As I understand it I need to load the controls in the OnPreInit method of the dashboard page, however I cannot get a reference to the Placeholder control at this point of initialization (i.e. I get a NullReferenceException); trying to load the Placeholder dynamically via Page.FindControl gives me, ironically, a StackOverflowException.
I've tried loading the controls in PreRender and OnInit as well but the events in the controls are not wired up properly and will not fire.
The code is basically this:
[code]....
View 2 Replies
Jun 10, 2010
Ive searched everywhere, i can't seem to find a way to implement ninject in my project. Ive heard of deriving MvcApplication to the NinjectHttpApplication. But NinjectHttpApplication isnt found even if i add the lib to the reference. I can't find Ninject.Web.Mvc. Does anyone have a guide somewhere in order to make this work, all i want to do is be able to bind my interface from my domain to existing implementation.
View 4 Replies
Feb 4, 2011
It's my understanding that if you want to use the WCF-Ninject extension, it assumes that you are hosting your WCF services in their own AppDomain.
I'm already using the Ninject.Web extension and asp.net compatibility mode to get at the Membership Provider and Session.
Is there a way utilize my Ninject with my WCF services that are hosted in the same AppDomain as my Web Application?
View 1 Replies
Mar 28, 2011
having trouble defining bindings using ninject.I am in a standard ASP.NET WebForms application. I have defined an http handler to Inject dependencies in pages and controls (Property injection).Here is what I am trying to do:I am creating a custom combobox usercontrol. Based on the value of an enum on that combobox, I want to be able to Inject a different object in a property (What I am trying to do is a bit more involved than that, but answer to this should be enough to get me going).
View 1 Replies
Sep 5, 2010
Is it possible to add a new object that Ninject should be responsible for (lifetime, injection etc.) in an ASP.NET application after the Application_Started event is fired?
My application needs to dynamically designate objects that should be tracked well after the application is started
View 2 Replies
Apr 11, 2010
I'm doing shared hosting with GoDaddy and I developed a sample ASP.NET MVC app using Castle Windsor and unfortunately, it didn't work in a medium trust setting. Specifically, I got this error: "[SecurityException: That assembly does not allow partially trusted callers"... etc. GoDaddy is sadly not flexible in their trust policy.
I'm not tied to Windsor and would like to try another one that will work under Medium Trust. I'd actually like to use NInject, but I've read people having mixed success. The only one I've read that works with no problem is Microsoft's Unity.My question is, does NInject work in medium trust? If not, what are my options?
View 2 Replies
Mar 4, 2011
I'm playing around with dependency injection in a web-forms website al a Ninject and whilst I have had no problem at all getting the site running smoothly I've had a pretty big problem when viewing individual pages using design mode.
I wouldn't normally use design mode but dragging and dropping web user controls onto a design space is the easiest way by far to add them to a page.
The set-up is pretty much identical to guidelines here The error on the design page is thus:
The type "page name" requests an injection, but no kernel has been registered for the web application. ensure that your project defines a NinjectHttpApplication.
I'm using Asp.Net 4.0 with Ninject and Ninject.Web 2.2 utilizing property injection
View 1 Replies
Dec 16, 2010
I have an aspx page that I would like to have injected a reference to a user control. The user control is stored in a seperate assembly and loaded at runtime. After injected the user control it should then be loaded into the control collection of the page.
Everything seems to be working fine expect the point of adding the control to the page. There is no error but the UI for the control doesn't show.
global.asax.cs
protected override Ninject.IKernel CreateKernel()
{
var modules = new INinjectModule[] { new MyDefaultModule() };
var kernel = new StandardKernel(modules);
// Loads the module from an assembly in the Bin
kernel.Load("ExternalAssembly.dll");
return kernel;
}
and here is how the external module is defined in the other assembly:
public class ExternalModule : NinjectModule
{
public ExternalModule() { }
public override void Load()
{
Bind<IView>().To<controls_MyCustomUserControlView>();
}
}
The debugger shows that when the app is run, the Load on the external module is being called, and the dependency gets injected into the page.
public partial class admin_MainPage : PageBase
{
[Inject]
public IView Views { get; set; }
At this point when trying to add the view (here a user control) to the page, nothing is shown. Is this something to do with the way the user control is created by Ninject? The loaded control seems to have an empty control collection.
inside aspx page
var c = (UserControl)Views;
// this won't show anything. even the Control collection of the loaded control (c.Controls) is empty
var view = MultiView1.GetActiveView().Controls.Add(c);
// but this works fine
MultiView1.GetActiveView().Controls.Add(new Label() { Text = "Nice view you got here..." });
and finally the view/user control:
public partial class controls_MyCustomUserControlView : UserControl, IView
{
}
It contains just one label:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyCustomUserControlView.ascx.cs" Inherits="controls_MyCustomUserControlView" %>
<asp:Label Text="Wow, what a view!" runat="server" />
View 1 Replies
Oct 9, 2010
Im trying to implement an unit of work pattern by passing an unit of work instance into my repositories.
Relevant code from Global.asax.
[code]....
What i want is that a maximum of 1 instance of SqlUnitOfWork is created per request and is passed into my repositories (via their respective constructors).
Is the InRequestScope() method on the IUnitOfWork binding enough? If not how can i achieve this?
View 1 Replies
Jan 24, 2011
ive tried to build some base project with above technologies. I wanted maximum flexibility and testability so i tried to use patterns along the way to make this as a base for future projects. However, it seem.something is wrong or whatever and i really need help here. So
i have two questions :1- Is there anything wrong with my current code ? Ive applied patterns correctly ?
2- Why do this code actually connect to the database, create it, but doesnt support insert even if i perform the corrects operation ? (Look at the end of the post for details about this error)
I have two entities : Comment and Review
COMMENT [Code]....
REVIEW[Code].... I built up a base repository for each of them this way :GENERIC REPOSITORY[Code]...For specific operations, i use an interface :[Code]....So i am getting the generics operations from the abstract class plus the specific operations :[Code]....As you figured out, i also use a database factory will produce the database context :DATABASE FACTORY [Code]....DISPOSABLE (Some extensions methods...)[Code]....DATABASE [Code]....And to finish, i have my unit of work....UNIT OF WORK[Code]....I also binded using Ninject the interfaces :NINJECT CONTROLLER FACTORY [Code]....however, when i call in the constructor ...[Code]....
This seem to create the database but doesnt't insert anything in the database in EF4. It seem that i may figured out the problem.. while looking at the database object.. the connection state is closed and server version throw an exception of this kind :
ServerVersion = '(((System.Data.Entity.DbContext (_database)).Database.Connection).ServerVersion' threw an exception of type 'System.InvalidOperationException'
I am doing the right things ? Is there anything wrong in what ive built ? Also if you have recommandation about the code i posted, i would be glad. I am just trying to the learn the right way for building any kind of application in MVC 3. I want a good a start.
I use :
- Entity Framework 4 Code-First CTP 5
- ASP.NET MVC 3
- Ninject as DI Container
View 4 Replies
Aug 6, 2010
I will like to add Rhino Service Bus to my ASP.NET web application but using Ninject as the DI Container. So far all examples I keep seeing use Castle Windsor which I don't want to use since we already use Ninject.Are there any tutorials out there which show how to add Rhino Service Bus to an ASP.NET web application without a direct dependency on Castle Windsor (e.g. using Ninject)?
View 1 Replies
Nov 25, 2010
Just Wondering. Can we use Html Helpers/Repositary Pattern/Ninject in Webforms?
View 1 Replies
Feb 2, 2010
I'm trying to write my first server control. It's supposed to be a pager (like in the GridView Control Pageing-"thingy").
(It looks something like this : 1 2 3 4 5 6 7 8 9 10 ...)
I'm trying to implement it by making the control inherit Table properties and then adding two rows. One row has a hidden field that has the current selected page and the other has LinkButtons in individual TableCells.
The problem I'm facing is that the LinkButton.Click event only fires on the first 10 linkButtons but not the dots (...). What I mean is, when I press the dots (...) it renders like this: .... 11 12 13 14 15 16 17 18 19 20 ... BUT when I press any of these LinkButtons the control just "reloads" itself and renders from 1 to 10 ... (and the Event never fires) I don't know what I'm doing wrong but I think it has something to do with the "override" functions because I don't know which to use. I have tried quite a few but haven't found the right way to do this. The Code I got so far:
[Code]....
View 2 Replies
Oct 22, 2010
How to use cache dependencies in MVC?So far, I follow the caching tutorial (http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx) but what if changes occured in the database and the page is still cached. [:(]
How to clear cached pages when new data is inserted?
View 4 Replies
Mar 1, 2011
After about 30 Minutes the whole Unity Container is away, that means that all my Dependencies rises null exceptions, because they can't get resolved.
Global.asax:
[Code]....
[Code]....
View 3 Replies
Mar 8, 2011
When looking at ASP.NET MVC 3 and WebPages (the 'simple' web application framework used by WebMatrix) I noticed that these frameworks take a dependency on assemblies and/or namespaces that do not fit the familiar naming style for ASP.NET:
- Microsoft.Web.Infrastructure
- WebMatrix.Data
- WebMatrix.WebData
- Microsoft.Web.Helpers
Most if not all assemblies/namespaces up until and including ASP.NET 4 and ASP.NET MVC 2 are called *System.Web.** Why did they do it? Is this 'a trap' or is that too cynical? Some context (from the [Mono 2.10 Release Notes][1]):
> Although ASP.NET MVC3 is open source
> and licensed under the terms of the
> MS-PL license, it takes a few
> dependencies on new libraries that are
> not open source nor are they part of
> the Microsoft.NET Framework.
>
> At this point we do not have open
> source implementations of those
> libraries, so we can not ship the full
> ASP.NET MVC3 stack with Mono.
[URL]
View 4 Replies
Jan 11, 2010
I am trying to create an ASP.NET MVC application, using Spring.NET to inject dependencies. The application has three tiers: Controller, Service, and Data. I have defined the objects in the file "~Resourcesobjects.xml". My first object, UserAccountController, requires the injection of two Service-tier classes: UserAccountService and DepartmentService. So, the definition in objects.xml looks like this:
<object id="UserAccountController" type="App.Controllers.UserAccountController, App">
<constructor-arg index="0" ref="DepartmentService" />
<constructor-arg index="1" ref="UserAccountService" /> </object>
<object id="UserAccountService" type="App.Service.UserAccountService, App">
<property name="UserAccountDao" ref="UserAccountDao" /> </object>
<object id="UserAccountDao" type="App.Data.UserAccountDao, App" />
<object id="DepartmentService" type="App.Service.DepartmentService, App">
<property name="DepartmentDao" ref="DepartmentDao" /> </object>
<object id="DepartmentDao" type="App.Data.DepartmentDao" />
Webconfig contains this:
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
</sectionGroup> </configSections> <spring> <context>
<resource uri="~/Resources/objects.xml" /> </context> </spring>
I would prefer to use Property injection rather than constructor, but currently neither method is working.
View 3 Replies
Sep 9, 2010
Suppose i have an controller action that i would like to output cache.
public class HomeController : Controller
{
[OutputCache(Duration=10, VaryByParam="none")]
public ActionResult Index()[code]....
I need to dynamically set dependency to an external file inside the code. How can i do that?
View 2 Replies
Jan 13, 2010
I have an ASP.NET application which requires output caching. I need to invalidate the cached items when the data returned from a web service changes, so a simple duration is not good enough.
I have been doing a bit of reading about cache dependencies and think I have the right idea. It looks like I will need to create a cache dependency to my web service.To associate the page output with this dependency I think I should use the following method:
Response.AddCacheItemDependency(cacheKey);
The thing I am struggling with is what I should add to the cache?
The dependency my page has is to a single value returned by the web service. My current thinking is that I should create a Custom Cache Dependency via subclassing CacheDependency, and store the current value in the cache. I can then use Response.AddCacheItemDependency to form the dependency.
I can then periodically check the value and for a NotifyDependencyChange in order to invalidate my cached HTTP response.The problem is, I need to ensure that the cache is flushed immediately, so a periodic check is not good enough. How can I ensure that my dependant object in the cache which represents the value returned by the web service is re-evaluated before the HTTP response is fetched from the cache?
View 2 Replies
May 14, 2010
i have installed the ASPAJAXExtSetup into my system for using ajax because i am using .net 2.0 version. Then i have create the Ajax Enabled website. in myDescription: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The system cannot find the file specified.
Line 1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>
Line 2:
Line 3: <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
Line 4:
Line 5:
View 1 Replies
Sep 20, 2010
I work in a small developing team with 3 developers and none of us are really 'uber elite programmers' but we get by pretty well for our company. One thing that has been constantly recurring is we keep using the same resources in multiple projects. One example being the fckeditor control, however it stinks to constantly add this folder to every project (I've got the control set-up in my toolbox, but it won't be able to find the code unless you have the folder in there). This also applies with constantly recurring master pages and controls. Now we have made some steps for improving this, including making a 'back end' project where we put our shared functions, and made a CDN for images and scripts. But I still run into issues. For instance all developers must make sure they have the latest version of the back end project checked out, and built. Also when you add a reference to that .dll, the paths have to be the same between developers, otherwise it breaks the reference.
Now I just found out you can add a project reference, which will make the back end project build anytime I build the front-end project, but again you still have to make sure you have the latest version checked out. But I wonder what else I could do? Things I find annoying are making sure the relative locations of the back end project to the front end project has to be the same, and making sure they have the latest version of the back end checked out. Are there better ways to do this?Also the back-end project is a class library, but how can I share resources like a user control? I tried putting a user control in a normal project, and then adding that project as a reference, but it doesn't give you access to the control in the file list like I am used to for dragging into a page.
View 2 Replies