MVC :: Unity Container Dependencies
Mar 1, 2011After 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]....
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]....
what is unity of asp.net framework lib. how to use it.
what is the benifit of using this
I'm using Microsoft Unity. I have an interface ICustomerService and its implementation CustomerService. I can register them for the Unity container using the following code:
container.RegisterType<ICustomerService, CustomerService>(new TransientLifetimeManager());
If CustomerService has a certain parameter in its constructor (e.g. ISomeService1), I use the following code (I need to specify SomeService1):
container.RegisterType<ICustomerService, CustomerService>(new TransientLifetimeManager(), new InjectionConstructor(new SomeService1()));
No problems here. The problem appears when CustomerService class has two parameters (not one param as in the previous example) in its constructor (e.g. ISomeService1 and ISomeService2). It works fine when I'm using the following code: container.RegisterType(new TransientLifetimeManager(), new InjectionConstructor(new SomeService1(), new SomeService2()));The problem is that I do not want specify SomeService2() for the second parameter. I want to specify only first parameter - SomeService1(). But I get the error that I need to specify none or both of parameters. How can I specify only first parameter of constructor?
in my implementation, I have an interface as: ICachingManager. I've got now one implementation. I also created a manager class as:
public class CachingManager
{
#region Members
private ICachingManager service;
[Code]....
In case I had one implementation, then I can easily register the CachingManager class with Unity, automatically Unity resolves and injects the ICachingManager.
In case I had more than one implementation using named types, then how can I can make use of Unity? Do I need to make use of an Abstract Factory to decide on which named type to initialize?
Is it a good idea to make use of such a composite class or use directly implementations of the interface with Abstract Factory?
I am using unity, entity framework 4 with POCO classes, repository pattern for DAL and services for Business Logic control.I also want to use Unit of Work so I can package together CRUD operations which I perform on different services and then commit them all together.My question is what would be the proper way to inject the Unit Of Work mechanism into my application using Microsoft Unity?I understand that I can put the IUnitOfWork together with the repository on the constructor of the proper service and then if Unity mapping is specified it would auto initiate the proper instances, but this way I do not pass the global unit of work but rather create a new instance on each level, which can't be a smart way to do it (actually the repository is initiated even before the service).
private IUnitOfWork _uow;
/// <summary>
/// Returns the active object context
/// </summary>
private ObjectContext ObjectContext
[code]...
I would like to implement IOC and DI and have been looking at the various open source IOC's such as Unity, StructureMap, Ninject, and Castle Windsor, but I noticed that some of them are based on .Net 3.5 framework. Does this matter? Which IOC's would be most suitable or easily integrates for use in an MVC3, EF4, and .NET 4 framework application? Which would be the simplest to implement?
View 5 RepliesIm faced with an impending upgrade to an ASP.NET site and I am thinking of introducing DI using Unity. I have researched the ASP.NET DI side of things and have 2 options (Global.asax or IHttpModule). Im happy to use either. As always, there is a legacy object model in place that I would like to upgrade/change. I would like to go down the route of Constructor injection (passing in the DAO) however, each object has a mix of static and instance methods that both currently call into the DB using SqlCommand objects themselves. I want this removed to provide DB independence, therefore can anyone suggest the best way to do the DI in this case? Im open to drastic changes if they are needed.
public class ExampleClass
{
public ExampleClass(int test)
{
TestProperty = test;
}
public int TestProperty {get; set;}
public int Save()
{
// Call DB and Save
[Code]....
I have an ASP.NET web forms site using Master Pages. It is using Unity as my IoC container. I have created an HTTP Module to build up the container using a couple of tutorials i found online. I need the dependency injection to work for User Controls and the only way i was able to get this to work was to hook into the Pages PreInit event as can be seen from the code below.
[code]....
I also have autoeventwireup set to true on the pages and master page. Can anyone shed any light on why the events are not firing? Is my Unity http module causing this to happen by dropping the event wiring? I can get this to work no problem in a basic example with no IoC involved.
I have the following generic lifetime manager
[code]...
causes the following error
Cannot create an instance of UI.Common.Unity.RequestLifetimeManager`1[T] because Type.ContainsGenericParameters is true.How do you reference generic lifetime managers?
Does anyone have any good examples of how to make Unity 1.2 or 2.0 work with ASP.NET WebForms?
I thought I had this figured out, but evidently I'm missing something. Now I'm getting the error; "No parameterless constructor defined for this object". I remember getting this error a couple years ago, I and just don't remember what I did.
Obviously Unity isn't working as it should because somewhere along the way I've forgotten something.
Here's some of my code:
Global.asax
[code]....
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?
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]
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.
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?
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?
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?
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:
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.
How to develop program/website and minimize DB dependencies using C#.NET? For example I have made some changes in my DB, after that I must rewrite half a project.
View 2 Repliesi have installed AJAXcontrolsToolkit with my visual studio and placed "Combobox" Ajaxcontrol controls in my webpage . when i am compiling the code getting below error"Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The system cannot find the file specified"
View 1 RepliesI changed some names of namespaces, assemblies in one of existing project (C# and ASP.NET). But when I try to debug it; I get this error. Could not load file or assembly 'HR' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040). I have replaced DFI with HR in the code.
View 2 RepliesI am willing to follow the rules of the W3C where it is recommended that javascript and CSS files should be in individual files and not within the page.
Good, following this rule, and not wanting to overload the master page, I would like to embed the dependencies dynamically. So how could I insert the libraries dynamically? I think the bigger problem is the Ajax requests.
Example:
<script type="text/javascript" src="http://sstatic.net/so/js/master.js?v=6523"></script>
I tried using the JavascriptResult, but he writes the content on the page, and do not run as "Stream."
could not found file or assembli 'ajaxControlToolkit' or one of its dependencies. the module what expected to contain an assembly manifest. this error is comming when i debug my website. i"ve added dll file in bin folder of my website. what is the problem and how can it be solved?
View 2 RepliesThe full error is: Could not load file or assembly 'App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Where xxxxxxxx is the ASP.Net generated temp name. We are getting this error for a WCF service hosted within an ASP.Net application. The weird thing is that it happens very occasionally, independent of deployment changes... and when it does happen the service "breaks" for all subsequent requests. At the moment, the workaround for us at the moment is to delete the temporary assemblies from the application's folder in: %windir%Microsoft.NETFramework64v2.0.50727Temporary ASP.NET Files The app is hosted in IIS7 on a win 2008 server, using .Net 3.5
View 1 RepliesI received the following error message. After googling I cleared the ASP.net temp files
The error messwsage is: Could not load file or assembly 'AjaxControlToolkit' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)"