.net - Architecture With NHibernate And Repositories?

Apr 13, 2010

I've been reading up on MVC 2 and the recommended patterns, so far I've come to the conclusion (amongst much hair pulling and total confusion) that:

Model - Is just a basic data container Repository - Provides data access Service - Provides business logic and acts as an API to the Controller

The Controller talks to the Service, the Service talks to the Repository and Model. So for example, if I wanted to display a blog post page with its comments, I might do:

post = PostService.Get(id);
comments = PostService.GetComments(post); Or, would I do:

post = PostService.Get(id);
comments = post.Comments;

If so, where is this being set, from the repository? the problem there being its not lazy loaded.. that's not a huge problem but then say I wanted to list 10 posts with the first 2 comments for each, id have to load the posts then loop and load the comments which becomes messy.All of the example's use "InMemory" repository's for testing and say that including db stuff would be out of scope. But this leaves me with many blanks, so for a start can anyone comment on the above?

View 1 Replies


Similar Messages:

Web Application Architecture Using Nhibernate

Dec 10, 2010

I'm designing my first asp.net web app, using nHibernate as the data provider. i've read a lot about nhibernate in web applications using session-per-request pattern. my application will have a few pages which are 'monitors', meaning- they're updated automatically every few seconds to reflect recent changes to data. in that case, my thought is that opening a session for every request would not make much sense, since I know that an identical request is sure to follow in a few seconds. my thought is that session-per-conversation would make more sense for me, but I'm having trouble finding examples of implementations. I'd appreciate any good resources for how to implement session-per-conversation

View 2 Replies

MVC :: Are Repositories Automatically Disposed Of In C#?

Dec 6, 2010

Could someone explain what happens to the Repositories that are created when they are no longer needed? Are they automatically disposed of, or should we dispose of them manually?

Using EF4 as the DAL, to keep the program efficient I have been building repositories for the Model that abstract the data needed for specific views or actions. I have also used the Iinterface for the methods and call them in the Controller to pass them to the View. At some point the program needs to pass a behavior or request that requires the creation of a new repository and the process may repeat itself over and over again. What happens to the repositories that created for previous views, but are no longer needed? Should the dispose be written into each repository, or does garbage collection take care of this? How should this handled?

View 6 Replies

Traditional Repositories Vs Single UnitOfWork

Aug 17, 2010

I would like to start a debate on traditional repositories versus one built on the UnitOfWork pattern. In a traditional repository, we wrap inserts, updates and deletes in a transaction, but selects don't really need them. In addition, nhibernate configuration is typically done once per application due to BuildSessionFactory being rather expensive. We often have several repositories of this type (one per aggregate chain). We also need to have projected, ahead of time, exactly what kinds of queries we'll need in order to build the interfaces and concretes correctly. In a single UnitOfWork repository we have the ability to manage both the current session and transaction, perform several operations, and then commit any changes all at once. In such a repository we may opt to put our configuration in the constructor since (typically speaking) no more than one Action is called per request anyway, initializing it in the application doesn't seem like much of an overall gain in speed. I must admit, I'm very temped to use the UnitOfWork pattern, as the following code looks really nice to me:

Csharp Code:
using (IUnitOfWork worker = new UnitOfWork()){// session and transaction are now both set
// save changes to three itemsworker.SaveOrUpdate(item1);worker.SaveOrUpdate(item2);worker.SaveOrUpdate(item3);
// grab a fourth var item4 = worker.Criteria<Foo>().Add(Expression.Eq("title", title)).UniqueResult<Foo>();
// delete the fourthworker.Delete(item4);
// all pending operations are commited or rolled back as a single unit (if one fails, all are rolled back), and then disposed, along with the session}

My proposed UnitOfWork class is rather simple. It implements IDisposable where I use a try-catch-finally in Dispose() to attempt a tx.Commit(), doing a tx.Rollback on failure, and a cleaning everything up in the finally clause. It also exposes common things like SaveOrUpdate, Delete, GetAll, Get, and even a Critera<T>() for custom on-the-spot queries. So what are your thoughts on this? I'd really like to hear about your experience with this pattern.

View 4 Replies

Single Repository Or Multiple Repositories?

May 1, 2010

In a typical business application, a session is started and persisted across several pages. It is commited only when the transaction is complete. A good example of this is a tax preparation application. Once the session is started, it is persisted through session, cookies, or both. Nothing is written to file, or database, until the entire profile is complete and the refund/return is calculated. In such an ennvironment, is makes a great deal of sense to work with the structure imposed by domain driven design, and using a single repository to simple commit the session. However, there are times when this doesn't translate correctly, even when domain driven design is used.

An example of this is my forum project. While the entities themselves are good targets for domain driven design, I am not sure about the repositories. The basic structure is that a Category has many Forums, a Forum has many Threads, and a Thread has many posts. There are other things in there, but that's enough to describe what I want to get across. If a user has navigated to /Thread/Edit/42, and they have rights to edit it, all I am concerned about is fetching that record and displaying it. On postback, all I want is to be able to save it..................

View 2 Replies

C# - Are Repositories Useful Without Domain Driven Design?

Mar 9, 2011

Assuming my application did not warrant a full blown DDD setup, would Repositories still be useful? I like the way they shield from implementation details (such as use of Entity Framework) underneath. However Repositories tend to be tied to Aggregate Roots (the concept is still a holy grail to me) by definition.

I suppose the question could also be put as such: if I have a typical 3-tier application, with a business layer facade consisting of "logical grouping" classes based on functionality (rather than aggregate roots as in DDD) such as TradingManager and ContactsManager, would it make sense to also create "logical grouping" repositories. Or perhaps a Data Access Object, which I believe is like a Repository without the aggregate root requirement. Of course I will still have a Model (EF POCOs) that will be passed up and down between the layers.

Also, is what I just described would be considered as a Transaction Script approach? It's certainly not DDD, and not Active Record. I'm not even sure if Active Record exists with EF4 like it does with Nhibernate.

I am trying to understand how others structure n-layered applications when they do not follow DDD.

View 2 Replies

MVC :: Using EF4 Complex Types / Properties In Repositories?

Jan 13, 2011

Are there advantages in creating complex types in EF4 Entities and then use the complex properties in the repositories; instead of creating the aggregates in the the repository themselves? I.e. If the customer repository consists of properties of 3 entities: customers, addresses, email would it make sense to create a complex type consisting of the address and email properties, and add them as a complex property of the customer entity then just call the customer entity and the complex property in the repository, rather than just creating the repository class and aggregate the entities in the repository.What are there advantages or disadvantages in doing this in a MVC3 application?

View 10 Replies

MVC :: Multiple Repositories And Save DB Function

May 3, 2010

I have a few repositories in my project. All repositories inherit from an abstract interface repository containing the public datacontext variable and a Save function for the entire DB.

In my controllers I want to make changes to the the db and in one of my functions I'm working with two different repositories. Calling the Save function on each of the repositories I'm using can cause a situation in which one of the calls to Save succeeds and and the other fails resulting in a need of rolling back the changes of the Save function that failed.

What is the best way to work against multiple repositories and access to the DB to avoid such a situation?

View 7 Replies

DataSource Controls :: SubmitChanges In Controller (mvc) Using Repositories (linq2sql)?

Jul 7, 2010

I'm got 2 model objects. Category and CategoryItem. I try to add a CategoryItem to Category in my Controller but It wont save to database, and I know why because I don't know how to call the submitChanges on the add while using repository, I dont got the DBContext right there is you know what I mean?.. here I will show you with code.

[Code]....

View 4 Replies

C# - .net Development Code Structure -Controllers, Services, Repositories & Contexts?

Dec 11, 2010

As a new developer I'm getting thoroughly confused by naming and structural conventions for developing c# code using best practice.I appreciate it's perhaps applicable to each domain I am developing for but I've seen the code of many different open source projects and there seems to be a common theme. The successful projects have well thought out structure for maintenance and extensibility.The terms context, service, repository and controllers are used often and I wondered if these are open to interpretation or is there a consensus or convention on what, where or how these get used.

In an e-commerce platform I've seen there are order services, order contexts, customer repositories and product controllers for example. What should they do based on these names? Does a controller do something different to a service? When should you use a context? Is there a convention for namespaces? It's mind boggling when you try and push from a spoon fed newbie developer and try to move on.What software/tools should I really be looking at to develop quality code? Unit Testing, Continous Integration, Resharper, Mocking tools, DOI Containers, nHibernate.

I'm not really aware of blogs/books that will help me push on from being a proficient web developer into someone who can develop extensible, quality and testable code. There are big gaps in authors assumptions. You are either a newbie or a software architect. I want to push from being a junior developer with a long term aim of being a software architect. I realise it's all about patterns and practices but where are the training materials? I work on my own so don't have the opportunity of learning from others.

View 2 Replies

C# - Getting A Online Repositories And Project Management Tool For A Project?

Feb 16, 2010

Our team doing a project in asp.net & Mssql 2005.since our team member are distributed. we need a online tool for tracking project changes, and control access to our online code repositories.

[code]....

View 4 Replies

Architecture :: Articles/Links On Asp.Net Pipeline And Internal Request Processing Architecture?

Oct 4, 2010

I am looking details on the internal working of asp.net architecture. The topics need to include the following:

Asp.Net Thread/Application Pools HttpRuntime HttpApplication - When and how it is set up How HttpContext is set up How objects can passed along the pipeline using HttpContext.Current.Items Why does modification of static variables requires locks in ASP.NET (advanced)IIS 7 Integration Mode

View 1 Replies

Architecture :: How To Design A Centralized Business Or Service Authentication Architecture

Sep 22, 2010

i want to create a centralised business or Service authendication architecture in .net. for example, we have a clients like c1, c2, c3, c4, ... etc. everybody logins seperatly as well as grouply. ie, if client "C1" logins [with login authentication] he can access c2 , c3, c4 also without login authendication. So its like a google. if we enters gmail account, we can access orkut, picasa like that.. i need the cetralised architecture.

And, client "c1" seperately asks seperately how will be the authendication architecture.

so give me the single solution for both these two scenarios. how will be the architecture for these two and how is the Data Base (Login) Structure.

View 3 Replies

Architecture :: Entity Model Design Framework And N - Tier Architecture

Dec 25, 2010

recently i've studied on ADO.NET's Entity Model Framework and say 'wow' as ORM is one of the fevourite pattern i practice..but suddenly i've come to an ambiguous situation when i'm going to start. i usually follow the following 3-tier architecture..

1. UI Layer
2. BLL - business logic layer
3. DAL - Data Access Layer
a. DTO / DAO
b. Gateway (contains the sql query/stored procedure and connection with DB)

now when i'm going to use the Entity Model Design,where the DBML/ .edmx File should be placed? Because many a times i'm using the DBML file as DTO because of the mapped objects.. in the same time, sometimes DBML ( .edmx file in .NET 4.0) contains CRUD methods and stored procedured method as well as methods with different selection operations,- which should be in Gateway. so where the .edmx file should be placed !?!! IN DTO namespace !? or in Gateway namespace!

moreover sometimes there is no need for the BLL which breaks the rules of inter-layer-communication (UI > BLL > DAL.Gateway)! what makes me confuse is, what should be the ideal n-tier architecture when i'll use the ADO.NET Entity Model Design Framework

View 4 Replies

Architecture :: Asynchronous Page Processing In 3 Tier Architecture?

Jul 30, 2010

I am working on 3 tier architecture: UI, BL, DAL. In my UI i have following code for Asynchronous page processing:

[Code]....

But I want a database fetch operation to be performed in this asyncronous method. And due to 3 tier arch. i am unable to do this in UI Layer. Can anyone guide me that how can I implement Asynchronous processing in 3 tier architecture? Note: If you are going to place EndAsyncWork1 in DAL then show that how can I return a value back to UI layer from this function.

[Code]....

View 1 Replies

Architecture :: What Is The Difference In 3-tier Architecture And Gereral Way Of Programming

May 20, 2010

I want to know that What are the factors if we use methods on each .cs page for connection and executing query on each aspx code behind page rather then using BAL .

How our application get affected in terms of performance and speed or other way?

when we put our website on server after publish/compile in general approach (using query in C# code behind) rathor than using stored procedures?

then which logic is better and why ?

View 8 Replies

Architecture :: Function Implementation In 3-tier Architecture?

Apr 28, 2010

I have implemented the 3-tier architecture project; DAL, BAL, and presentation layer are three layers in it. I am going to implement the following scenario:

Presentation layer calls to a function in the BAL layer which returns 2 string variable, and in turn this function from BAL layer calls to a DAL layer function which also returns 2 string variable. How can I implement the above scenario?

View 2 Replies

Architecture :: Exception Layer In N-tier Architecture?

May 13, 2010

I'm developing a n-tier architecture... I'm confused with handling exception in the layers... Is it a good practise to add a Exception Layer to the architecture.

View 3 Replies

Architecture :: Design Pattern And Tier Architecture

Jun 12, 2010

I am a newbie to asp.net and work in a firm where the projects are quite small.

I was told by my manager that in a few weeks or so we would be getting a bigger project and I need to be well versed with Design Patterns and N tier arcihtecture.

I would really appreciate if someone could provide me some links and also drop me a few sentences on how this things are useful?

View 4 Replies

Architecture :: Architecture FOR SAAS ( Service As A Product)?

Dec 22, 2010

I am going to create the SAAS (Software as a service) Application. Can you please provide all the attributes that we have to consider in SAAS application (for example usability, pluggable architecture etc .. )

How architecture should be build for this project, provide sample architecture for SAAS application. This architecture should be easy to upload and upgrade or degrade the features. Error handling should be easy.

View 2 Replies

Architecture :: Create architecture design For WCF Service?

Aug 10, 2010

I am try to create architecture design for WCF service.

We have WCF service that we have to expose to third party so then can request with xml and get back xml response.

The wcf service should do the following:

- Accept the request call with xml

- Check xml against the schema

- Parse the xml

- Authenticate the incoming xml by username and password that will be in xml

- Send back the response

If anybody can let me know what kind of design I can use or is there any pattern available that I can take it and then extend it as per my requirement.

View 2 Replies

Architecture :: Plugins Architecture O Nasp.net Webforms?

Mar 9, 2011

It's Possing to make a web site a web site to be extended using plugins?im planing to make a bugtracker using the webforms in aps.netbut icant find a tutorial about how to make it extendable

View 3 Replies

Architecture :: Is Layered Architecture A Pattern

Mar 2, 2010

guide in typical 4 layered architecture (having User Interface, Custom Types, Business Logic, Data Access Layer) do we follow some design pattern ? I am not clear what pattern it is or what pattern it should be called.

View 3 Replies

JQuery :: Architecture ( Javascript Architecture )?

Feb 5, 2011

am creating service oriented application , I am calling all my services through jquery but I am having a problem that I dont feel writing jquery calling scripts from the page and exposing the service names is something goood....like at least I shall have only one class that's calling , so...I am having some kind of problem to find the most suitable architecture about that

View 2 Replies

Architecture :: Trying To Use A 3-tier Architecture (UI, BAL & DAL) For Project?

Nov 30, 2010

I am trying to use a 3-tier architecture (UI, BAL & DAL) for my project. I have each of the tier in different physical machines.

UI - Machine 1
BAL - Machine 2
DAL - Machine 3
How can DAL & BAL interact? What would be the best way to call one component from another?

View 9 Replies







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