.net - Proper Way Of Using Unit Of Work With Unity Injection

Mar 7, 2011

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]...

View 2 Replies


Similar Messages:

How To Pass Unit Of Work Container Into Constructor Of Repository Using Dependency Injection

Jul 23, 2010

how to complete my implementation of the Repository pattern in an ASP.NET web application.

At the moment, I have a repository interface per domain class defining methods for e.g. loading and saving instances of that class.

Each repository interface is implemented by a class which does the NHibernate stuff. Castle Windsor sorts out the DI of the class into the interface according to web.config. An example of an implemented class is provided below:

[code].....

As pointed out in a previous thread, the repository class needs to accept an unit of work container (i.e. ISession) rather than instantiating it in every method.

I anticipate that the unit of work container will be created by each aspx page when needed (for example, in a property).

How do I then specify that this unit of work container instance is to be passed into the constructor of StoredWillRepository when Windsor is creating it for me?

View 4 Replies

C# - Best Way To Integrate Dependency Injection Using Unity When Static Methods Are Used?

Mar 8, 2010

Im 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]....

View 1 Replies

Should The Unit Of Work By Used By The Service Layer Or The Repository

Jan 26, 2011

In an ASP.NET MVC3 environnement with entity framework. Should the Unit of Work point to the service layer or the repository (and then the repository point to the service layer) ?

Ive saw two example:

* One where the unit of work and repository both have an instance to the service layer..

Link: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable

Doesn't use a service layer but its obvious that one could be use in that case.

* Second where the unit of work have an instance to the repository which have an instance to the service layer..

[URL]

View 16 Replies

Architecture :: EF4 With Repository And Unit Of Work Patterns?

Sep 26, 2010

I've been reading recently about EF4, and how to build an architecture for asp.net web forms application using it.

I explored using POCOs (self tracking entities), with WCF, but found out that my application will be deployed on a single box (i.e. one tier), so I started reading about logical separation of layers, and came up with the following solution:

DAL layer that contains EDMX model and EF APIs, and also generated context object.Entities DLL that holds all generated POCO entities using ADO.NET POCO entity generator. (for persistence ignorance, and decoupling entities from DAL).Business layer that contains a façade for each related group of business functions, the façade will be aware of and using DAL layer. And in each function, it will initiate context and uses different entities to carry out specific job (i.e. function).UI layer that only calls the business layer façade classes. With no awareness of DAL, but it will be aware of entities (i.e. using entities DLL), as the business layer will return results basically as entity collections.

I want to know what you think about this architecture.

I also read about an architecture that uses repository and unit of work patterns, but what I understand that context object is already implementing a UOF pattern, and also object sets are implementing repository pattern (correct me if I'm wrong), so the only advantage of using additional abstraction over them is to make the business layer communicates to my classes, not EF classes, and this is good only if the DAL strategy might change (i.e. by using another tool other than EF, which is not my plan).

View 8 Replies

DataSource Controls :: How To Use 1 Database Connection In A Unit Of Work Initiated From The UI

May 4, 2010

I am designing a web application and have separate layers for UI, BAL, DAL and DB, while using custom business objects and collections. The app will be used by over 10,000 + registered used and it becoming more complex as I add new functionality such as inline editing and batch processing of collections with transactions ... which has me up late at night trying to design the best approach for this ...In some UI web forms, I bind say 3 controls to 3 different collections. The UI calls the BAL classes for the required collections, then binds the collection returned. So for each collection I want, a db connection is opened and closed. As I understand database connectivity adds overhead so Is there anyway I can design this so 1 database connection is created for a unit of work in a 3-tier or n-tier architecture?

View 7 Replies

Unit Testing Error - The Unit Test Adapter Failed To Connect To The Data Source Or To Read The Data

May 6, 2010

I'm using VSTS 2K8 and I've set up a Unit Test Project. In it, I have a test class with a method that does a simple assertion. I'm using an Excel 2007 spreadsheet as my data source.

My test method looks like this:

[Code]....


As indicated in the method decoration attributes, my Excel spreadsheet is on my local C:/ Drive. In it, the sheet where all of my data is located is named "Sheet1".I've copied the Excel spreadsheet into my project and I've set its Build Action = "Content" and I've set its Copy to Output Directory = "Copy if Newer".

When trying to run this simple unit test, I receive the following error:

The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library. Error details: ERROR [42S02] [Microsoft][ODBC Excel Driver] The Microsoft Office Access database engine could not find the object 'Sheet1'. Make sure the object exists and that you spell its name and the path name correctly.

I've verified that the sheet name is spelled correctly (i.e. Sheet1) and I've verified that my data sources are set correctly.Web searches haven't turned up much at all.
[Code]....

View 5 Replies

What Is Unity In Dot Net

Sep 17, 2010

what is unity of asp.net framework lib. how to use it.

what is the benifit of using this

View 3 Replies

MVC :: Unity Container Dependencies

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

Microsoft Unity. Specify A Certain Parameter In Constructor?

Oct 30, 2010

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?

View 3 Replies

Registering Composite Classes In Unity?

Nov 25, 2010

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?

View 1 Replies

MVC :: Unity Setup - Which IOC's Are Most Suitable For MVC3 & EF4, And .Net 4 Framework

Jan 19, 2011

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 Replies

GridView OnRowEditing Events Not Firing When Using Unity 2.0 HTTP Module?

Jan 31, 2011

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.

View 1 Replies

Asp.net - Working With Generic Lifetime Managers In Unity Config Section

Apr 28, 2010

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?

View 1 Replies

C# - Making Unity And WebForms Error - No Parameterless Constructor Defined For This Object

Sep 7, 2010

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]....

View 2 Replies

Architecture :: Should The Unit Of Work Point To The Service Layer Or The Repository And Then The Repository Point To The Service Layer

Jan 26, 2011

Just wondering, in an ASP.NET MVC3 environnement with entity framework. Should the Unit of Work point to the service layer or the repository (and then the repository point to the service layer) ?

Ive saw two example:

* One where the unit of work and repository both have an instance to the service layer..

Link: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable

Doesn't use a service layer but its obvious that one could be use in that case.

* Second where the unit of work have an instance to the repository which have an instance to the service layer..

[URL]

What would be better ?

View 11 Replies

How To Get RSS Feed Injection

Dec 15, 2010

I want to display the world's top 100 IT giants list up-to-date on my webapge. from where can i get the informaiton? Is it possible to get the RSS feed for this?

View 4 Replies

Security :: SQL Injection Using Like %?

Feb 22, 2010

I want to know how my data could be compromised using a statemnt like SELECT [ID], [item], [price] FROM [Items] where item LIKE '%' + mitem + '%'" what line of could be considered an attack to the data.

View 16 Replies

Web Config Safe From SQL Injection And XSS

Nov 12, 2010

I've a blog-driven ASP.NET website. Under the post, there is a Comment block to let readers post comments.I've used some TextBoxes and TextArea for that.To Prevent XSS:I've filtered the input by using: Server.HtmlEncode() Method (I don't care about text formatting).To Prevent SQL-Injection:I'm using Linq To SQL (that should be like parametrized queries I think!).

ArticlesDataClasses dc = new ArticlesDataClasses();
ArticleComment newComm = new ArticleComment()
{
ArticleID = int.Parse(Request.QueryString["ArticleID"]),
CommentAuthor = Server.HtmlEncode(txtName.Text),
CommentText = Server.HtmlEncode(txtComment.InnerHtml).Replace("
", "<br />"),
CommentAuthorEmail = Server.HtmlEncode(txtMail.Text),
CommentTime = DateTime.Now,
Enabled = false
};

View 1 Replies

C# : Dependency Injection And Roles?

Jul 20, 2010

I have a page using an injected BLL service: a simple service returning a set of objects with a function like this:

public IMyService { List<Foo> All(); }

There is a default implementation for normal users.Now, i need that users in administrative role can view more objects, with another implementation of the service.Where can i configure my page to use the second implementation?

My first solution is to put the dependency to the IUnityContainer in the page, and use it to resolve the dependency:

[Dependency]
public IUnityContainer Container { get; set;}

Page_Init(..) [code].....

it's a ServiceLocator and it's neither scalable neither testable.

View 2 Replies

C# - .NET Module Dependency Injection?

Jan 3, 2011

During the design of a new generic authentication framework for some of our products, I have come across an architectural issue I cannot seem to find a good solution for.I have tried to simplify the problem in order to easily explain it.

The library has two classes:

Manager Is responsible for storing currently authenticated users.Module It is the responsibility for the module to validate each request according to security policies. The Module must ask the manager to determine whether a user is currently authenticated.

Now the manager is supplied an implementation of an interface which allows the manager to load users from a repository. The specific implementation is not contained in this library. Because of this, I cannot directly instantiate an instance of the repository within the library.

I have no way of modifying properties or supplying arguments for the module constructor. So my question is this, how can I give the module a reference to an instance of the Manager?

namespace Demo
{
public interface IRepository
{[code].....

View 4 Replies

Prevent Data From SQL Injection

Apr 14, 2010

prevent my data from SQL injection. I have replaced ' with '' (single quote with 2 quote) while doing any operation on sql server. tell me what all i need to do , to prevent my application from SQL injection. my application is in asp.net 2.0 i will use parameterized queries but what about my old projects.. i mean what about where i have written a string query and sending it to sql server as a commandtext. can any one insert sql injection even i have replaced ' with ''?

View 3 Replies

Security :: Sql Injection To My Website

May 9, 2010

i almost finished my website

but i am afraid of sql injection to my website

how i can protect my self against this injection ...?

View 3 Replies

VS 2010 - Protect From SQL Injection Where If A Is Put In End Of URL

Jul 22, 2011

How to protect from sql injection where if a ' is put in the end of the URL there is an error ?

View 12 Replies

The Proper Use Of EnsureChildControls()?

Sep 21, 2010

Most often I use it when I am accessing a property of a composite control that depends on a child control.But I have also added it to OnInit of a control so I could make sure a hidden field was added correctly. Just a minute ago I called it in RenderControl because I was having an issue rendering a calendar extender and it fixed it. I am starting to get a little confused on when I need to and when I don't need to call EnsureChildControls and when I should call it.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved