Rectangle 27 30

Comparison with the MVC architecture

At first glance, the three tiers may seem similar to the model-view-controller (MVC) concept; however, topologically they are different. A fundamental rule in a three tier architecture is the client tier never communicates directly with the data tier; in a three-tier model all communication must pass through the middle tier. Conceptually the three-tier architecture is linear. However, the [model-view-controller] MVC architecture is triangular: the view sends updates to the controller, the controller updates the model, and the view gets updated directly from the model.

The MVC architecture is not necessarily triangular, it can be either. However, the n-tiers architecture is always linear.

check the picture in this video or this article, hope helps someone.

So, which architecture (among linear and triangular) is better and why?

model view controller - what is the difference between 3 tier architec...

model-view-controller architecture three-tier
Rectangle 27 24

Having struggled with this question before, I have in various instances gone with all three. In general, most of the opinions I've seen favor duplication in an MVC project, with a ViewModel constructed specifically for each view. In this manner the convention you'd use is something like UserDetailsViewModel and UserCreateViewModel. As you said, at that point AutoMapper or some other auto mapping tool would be used to convert from your domain objects to these flat ViewModels.

While I, too, don't like repeating code, I also don't like polluting my domain objects with validation or other view-specific attributes. Another advantage, though admittedly one almost nobody would ever have to contend with (regardless of what all the pros say), is that you can manipulate your domain objects in some ways without necessarily manipulating your ViewModels. I mention that because it's commonly cited, not because it carries much weight for me.

Lastly, using a truly flat ViewModel makes for cleaner markup. When I've used composition, I've often made errors creating HTML elements with names that are something like User.Address.Street. A flat ViewModel reduces at least my likelihood of doing that (I know, I could always use HtmlHelper routines to create elements, but that's not always feasible).

My recent projects have also pretty much required separate ViewModels these days anyway. They've all been NHibernate-based, and the use of proxies on NHibernate objects makes it not possible to use them directly for views.

yes, one view model per view (in most cases), and automapper to avoid passing back and forth stuff, the thing with the other approaches is that you end up mixing concerns, and there is data that is not always required in the view (then you have to exclude fields, etc), or multiple objects required in the view, a view model can flatten all of that and have that responsiblity plus the data annotations stuff

Yup, that's another article I referenced to get to where I'm at now. I'm not 100% happy, though. In particular the overlap between my Edit and Create ViewModels is annoying. That's duplication I can't argue away as easily.

Also, do not confuse duplication with a violation of DRY. Just because you have properties of the same name on two entities does not mean you're repeating yourself. Syntactically, yes, but conceptually, your viewmodel and your entity are completely different -- especially when you're beyond a simple CRUD application.

c# - ASP.NET MVC Architecture : ViewModel by composition, inheritance ...

c# .net asp.net-mvc architecture
Rectangle 27 4

I am building an app that is a combination of MVC on the server and AngularJS on the client.

I found the easiest thing to do was to build a bunch of RESTful web api's to provide data services to the client. I also perform validation on the server to make sure that no one cheats (sending data using a client other than the web page). I also assemble the web page (though a controller and minimal view) to load all of the libraries it needs. Since I am building the web page with almost no changes from the view to the final HTML, I should be able to replace AngularJS with something else.

On the client, I used AngularJS to handle everything from calling the web api's to local validation. It gives the user the "immediate" response that is being pushed by the latest push on the web. You can make your page dynamic or relatively static. By using an architecture that is using a separation of concerns, I can replace the back end with anything that supports a RESTful api.

asp.net-mvc angularjs mvc
Rectangle 27 30

At first glance, the three tiers may seem similar to the MVC (Model View Controller) concept; however, topologically they are different. A fundamental rule in a three-tier architecture is the client tier never communicates directly with the data tier; in a three-tier model all communication must pass through the middleware tier. Conceptually the three-tier architecture is linear. However, the MVC architecture is triangular: the View sends updates to the Controller, the Controller updates the Model, and the View gets updated directly from the Model.

Sounds good, but I don't believe "the View gets updated directly from the Model" is a good idea. It doesn't make sense to use the Controller for updates and inserts but not for selects and filters, and I don't see the point of separation of concerns only to bind the view to the model anyway! Conclusion - MVC is another one of those obfuscations created by .... have a guess. I don't recall 3-tier ever being limited to "system architecture" or "application design". The central concept is separation of concerns.

It would depend on what you're doing. An MVC app for an iOS application (which likely would not allow the the view to be updated directly from the Model) will be different than a Web app (which might). MVC is a paradigm, not an absolute way of doing things.

model view controller - MVC Vs n-tier architecture - Stack Overflow

model-view-controller n-tier
Rectangle 27 5

I would recommend you writing a custom view engine. This way your structure might look like this:

And then have a custom view engine:

public class CustomViewEngine : WebFormViewEngine
{
    public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
    {
        string ua = controllerContext.HttpContext.Request.UserAgent;
        if (ua == "UA String 1")
        {
            return base.FindView(controllerContext, "UA1/" + viewName, masterName, useCache);
        }
        if (ua == "UA String 2")
        {
            return base.FindView(controllerContext, "UA2/" + viewName, masterName, useCache);
        }

        return base.FindView(controllerContext, viewName, masterName, useCache);
    }
}

And finally register the view engine in Application_Start:

ViewEngines.Engines.Clear();  
ViewEngines.Engines.Add(new CustomViewEngine());

This way your controller and actions are strictly the same and based on the User-Agent HTTP header the proper view will be used. All you need to do when you have to handle UA3 is to add the corresponding view in a UA3 folder. No need to touch the controllers and models.

asp.net mvc 2 - Best MVC architecture for multiple different known bro...

asp.net-mvc-2 architecture
Rectangle 27 6

You could also consider independent classes for domain and view models, in this case for example

public class EditUserModel {    
  public string Name { get; set; }    
  public string Email { get; set; }    
  public string Password { get; set; }        
  public string ConfirmPassword { get; set; }        
}

if the Id is stored in the url. If you want to avoid the manual copy between the instances of User and EditorUserModel, AutoMapper can help you. This way you can easily decouple the password string in your view model from the password hash in your domain model.

I personally prefer this technique; having a set of 'ViewModel' classes that are specifically for views & client validation. This keeps my model completely separate from any UI concerns. I certainly couldn't live with a 'ConfirmPassword' property existing on my model.

This has the added benefit that it allows you to add properties to the Model without worrying about them being updated inadvertently, since the ViewModel doesn't contain those properties unless you explicitly add them. In other words, only those items in the ViewModel can be updated to the Model.

c# - ASP.NET MVC Architecture : ViewModel by composition, inheritance ...

c# .net asp.net-mvc architecture
Rectangle 27 5

Both are valid implementations, and, depending on your needs, can work well.

Your #1 is essentially describing the Active Record pattern, which is used by SubSonic, Castle, and lots of other ORM implementations.

Your #2 is essentially describing the Entity Framework/Hibernate/LightSpeed approach, where you are dealing with objects that are more conceptually related to your domain rather than to tables. Instead of your objects containing foreign key ID properties, they actually contain the other domain object references, which are then instantiated in an on-access basis.

Both ways are great. The Active Record approach is usually more intuitive for beginners and has potentially less pitfalls. EF-style can save a lot of base-level coding and dealing with FK's directly in code.

Edit: To be clear, what you describe in both situations is data access layer related, rather then strictly model related. However in reality you're pretty close, as most models tend to simply represent one or more of these types of objects.

design - MVC Architecture. Whats in a model? - Stack Overflow

design model-view-controller architecture
Rectangle 27 29

As someone that's authored an ASP.Net/Angular website, I can tell you that you're going to be way better off stepping away from using Razor to render your HTML where you can.

In my projects I've set up one razor view to render my main page (I'm using a single page app written in Angular), then I have a folder of straight .html files that I use as my templates for Angular.

The rest is done in ASP.Net Web API calls in my case, but you can also use MVC action with JSON results.

As soon as I switched to this architecture, things went a lot more smoothly for me, development wise.

I'm considering going down this route for a project, but how would you handle validation? I would like to re-use the validation I have setup on my C# view models and pass them down to use with client side javascript validation (such as jquery.validate or something similar). The other way would be to return errors from the server after sending a request to the WebApi controller and catch them to display to the user. I'm very new to AngularJs by the way but keen to get started.

Personally, I found it to be really simple to use both Angular's built-in validation on the client, and then use .NET's DataAnnotations validation on the server. I think trying to push the .NET stuff down to the client will probably end up being more headache than it's really worth.

+1 I agree 100% with Blesh. If you think life is tough with AngularJS & MVC, try integrating with Web Forms. Absolute nightmare. Trying to add ng-model to ListItems in a RadioButtonList?... que random wrapping span tags for you! I decided to completely scrap using the bloated .NET controls & just use use standard HTML elements. I then bind my form values to a POCO model on postback & let DataAnnotations take care of the server side validation FTW.

@blesh, while I agree it's probably the best approach given the constraints, you then have duplication of validation and therefore face the possibility of inconsistencies in how fields are validated.

Anything could post to an API, it's a different way to interact over the web. Present a service and write clients in whatever you want. So you're going to have that possibility regardless. Generating client-side validation from the server is sketchy business anyhow.

ASP.NET MVC Validation form with AngularJS - Stack Overflow

asp.net-mvc validation razor angularjs data-annotations
Rectangle 27 101

I have worked on a project that had similar pluggable architecture like the one you described and it used the same technologies ASP.NET MVC and MEF. We had a host ASP.NET MVC application that handled the authentication, authorization and all requests. Our plugins(modules) were copied to a sub-folder of it. The plugins also were ASP.NET MVC applications that had its own models, controllers, views, css and js files. These are the steps that we followed to make it work:

We created engine based on MEF that discovers all composable parts at application start and creates a catalog of the composable parts. This is a task that is pefromed only once at application start. The engine needs to discover all plugable parts, that in our case were located either in the bin folder of the host application or in the Modules(Plugins) folder.

public class Bootstrapper
{
    private static CompositionContainer CompositionContainer;
    private static bool IsLoaded = false;

    public static void Compose(List<string> pluginFolders)
    {
        if (IsLoaded) return;

        var catalog = new AggregateCatalog();

        catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")));

        foreach (var plugin in pluginFolders)
        {
            var directoryCatalog = new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", plugin));
            catalog.Catalogs.Add(directoryCatalog);

        }
        CompositionContainer = new CompositionContainer(catalog);

        CompositionContainer.ComposeParts();
        IsLoaded = true;
    }

    public static T GetInstance<T>(string contractName = null)
    {
        var type = default(T);
        if (CompositionContainer == null) return type;

        if (!string.IsNullOrWhiteSpace(contractName))
            type = CompositionContainer.GetExportedValue<T>(contractName);
        else
            type = CompositionContainer.GetExportedValue<T>();

        return type;
    }
}

This is the sample code of the class that performs discovery of all MEF parts. The Compose method of the class is called from the Application_Start method in the Global.asax.cs file. The code is reduced for the sake of simplicity.

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        var pluginFolders = new List<string>();

        var plugins = Directory.GetDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules")).ToList();

        plugins.ForEach(s =>
        {
            var di = new DirectoryInfo(s);
            pluginFolders.Add(di.Name);
        });

        AreaRegistration.RegisterAllAreas();
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        Bootstrapper.Compose(pluginFolders);
        ControllerBuilder.Current.SetControllerFactory(new CustomControllerFactory());
        ViewEngines.Engines.Add(new CustomViewEngine(pluginFolders));
    }
}

It is assumed that all plugins are copied in a separate sub-folder of the Modules folder that is located in the root of the host application. Each plugin subfolder contains Views sub-folder and the dll from each plugin. In the Application_Start method above are also initialized the custom controller factory and the custom view engine which I will define below.

Creating controller factory that reads from MEF

Here is the code for defining custom controller factory which will discover the controller that needs to handle the request:

public class CustomControllerFactory : IControllerFactory
{
    private readonly DefaultControllerFactory _defaultControllerFactory;

    public CustomControllerFactory()
    {
        _defaultControllerFactory = new DefaultControllerFactory();
    }

    public IController CreateController(RequestContext requestContext, string controllerName)
    {
        var controller = Bootstrapper.GetInstance<IController>(controllerName);

        if (controller == null)
            throw new Exception("Controller not found!");

        return controller;
    }

    public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
    {
        return SessionStateBehavior.Default;
    }

    public void ReleaseController(IController controller)
    {
        var disposableController = controller as IDisposable;

        if (disposableController != null)
        {
            disposableController.Dispose();
        }
    }
}

Additionally each controller must be marked with Export attribute:

[Export("Plugin1", typeof(IController))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class Plugin1Controller : Controller
{
    //
    // GET: /Plugin1/
    public ActionResult Index()
    {
        return View();
    }
}

The first parameter of the Export attribute constructor must be unique because it specifies the contract name and uniquely identifies each controller. The PartCreationPolicy must be set to NonShared because controllers cannot be reused for multiple requests.

Creating View Engine that knows to find the views from the plugins

Creation of custom view engine is needed because the view engine by convention looks for views only in the Views folder of the host application. Since the plugins are located in separate Modules folder, we need to tell to the view engine to look there also.

public class CustomViewEngine : RazorViewEngine
{
    private List<string> _plugins = new List<string>();

    public CustomViewEngine(List<string> pluginFolders)
    {
        _plugins = pluginFolders;

        ViewLocationFormats = GetViewLocations();
        MasterLocationFormats = GetMasterLocations();
        PartialViewLocationFormats = GetViewLocations();
    }

    public string[] GetViewLocations()
    {
        var views = new List<string>();
        views.Add("~/Views/{1}/{0}.cshtml");

        _plugins.ForEach(plugin =>
            views.Add("~/Modules/" + plugin + "/Views/{1}/{0}.cshtml")
        );
        return views.ToArray();
    }

    public string[] GetMasterLocations()
    {
        var masterPages = new List<string>();

        masterPages.Add("~/Views/Shared/{0}.cshtml");

        _plugins.ForEach(plugin =>
            masterPages.Add("~/Modules/" + plugin + "/Views/Shared/{0}.cshtml")
        );

        return masterPages.ToArray();
    }
}

Solve the problem with strongly typed views in the plugins

By using only the above code, we couldn't use strongly typed views in our plugins(modules), because models existed outside of the bin folder. To solve this problem follow the following link.

how about custom route for each individual module? i think each moduleneed to get ref of routetable and global asax should have route interface in which the route interface will look both in module folder and core.

We solved that by defining separate area for each plugin. In each plugin we created a class that inherits from AreaRegistration and by overriding the RegisterArea method we were able to define routes that we wanted to use in the plugins.

i agree with cpoDesign. a sample project would be nice

c# - MEF with MVC 4 or 5 - Pluggable Architecture (2014) - Stack Overf...

c# asp.net .net asp.net-mvc mef
Rectangle 27 100

I have worked on a project that had similar pluggable architecture like the one you described and it used the same technologies ASP.NET MVC and MEF. We had a host ASP.NET MVC application that handled the authentication, authorization and all requests. Our plugins(modules) were copied to a sub-folder of it. The plugins also were ASP.NET MVC applications that had its own models, controllers, views, css and js files. These are the steps that we followed to make it work:

We created engine based on MEF that discovers all composable parts at application start and creates a catalog of the composable parts. This is a task that is pefromed only once at application start. The engine needs to discover all plugable parts, that in our case were located either in the bin folder of the host application or in the Modules(Plugins) folder.

public class Bootstrapper
{
    private static CompositionContainer CompositionContainer;
    private static bool IsLoaded = false;

    public static void Compose(List<string> pluginFolders)
    {
        if (IsLoaded) return;

        var catalog = new AggregateCatalog();

        catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")));

        foreach (var plugin in pluginFolders)
        {
            var directoryCatalog = new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", plugin));
            catalog.Catalogs.Add(directoryCatalog);

        }
        CompositionContainer = new CompositionContainer(catalog);

        CompositionContainer.ComposeParts();
        IsLoaded = true;
    }

    public static T GetInstance<T>(string contractName = null)
    {
        var type = default(T);
        if (CompositionContainer == null) return type;

        if (!string.IsNullOrWhiteSpace(contractName))
            type = CompositionContainer.GetExportedValue<T>(contractName);
        else
            type = CompositionContainer.GetExportedValue<T>();

        return type;
    }
}

This is the sample code of the class that performs discovery of all MEF parts. The Compose method of the class is called from the Application_Start method in the Global.asax.cs file. The code is reduced for the sake of simplicity.

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        var pluginFolders = new List<string>();

        var plugins = Directory.GetDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules")).ToList();

        plugins.ForEach(s =>
        {
            var di = new DirectoryInfo(s);
            pluginFolders.Add(di.Name);
        });

        AreaRegistration.RegisterAllAreas();
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        Bootstrapper.Compose(pluginFolders);
        ControllerBuilder.Current.SetControllerFactory(new CustomControllerFactory());
        ViewEngines.Engines.Add(new CustomViewEngine(pluginFolders));
    }
}

It is assumed that all plugins are copied in a separate sub-folder of the Modules folder that is located in the root of the host application. Each plugin subfolder contains Views sub-folder and the dll from each plugin. In the Application_Start method above are also initialized the custom controller factory and the custom view engine which I will define below.

Creating controller factory that reads from MEF

Here is the code for defining custom controller factory which will discover the controller that needs to handle the request:

public class CustomControllerFactory : IControllerFactory
{
    private readonly DefaultControllerFactory _defaultControllerFactory;

    public CustomControllerFactory()
    {
        _defaultControllerFactory = new DefaultControllerFactory();
    }

    public IController CreateController(RequestContext requestContext, string controllerName)
    {
        var controller = Bootstrapper.GetInstance<IController>(controllerName);

        if (controller == null)
            throw new Exception("Controller not found!");

        return controller;
    }

    public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
    {
        return SessionStateBehavior.Default;
    }

    public void ReleaseController(IController controller)
    {
        var disposableController = controller as IDisposable;

        if (disposableController != null)
        {
            disposableController.Dispose();
        }
    }
}

Additionally each controller must be marked with Export attribute:

[Export("Plugin1", typeof(IController))]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class Plugin1Controller : Controller
{
    //
    // GET: /Plugin1/
    public ActionResult Index()
    {
        return View();
    }
}

The first parameter of the Export attribute constructor must be unique because it specifies the contract name and uniquely identifies each controller. The PartCreationPolicy must be set to NonShared because controllers cannot be reused for multiple requests.

Creating View Engine that knows to find the views from the plugins

Creation of custom view engine is needed because the view engine by convention looks for views only in the Views folder of the host application. Since the plugins are located in separate Modules folder, we need to tell to the view engine to look there also.

public class CustomViewEngine : RazorViewEngine
{
    private List<string> _plugins = new List<string>();

    public CustomViewEngine(List<string> pluginFolders)
    {
        _plugins = pluginFolders;

        ViewLocationFormats = GetViewLocations();
        MasterLocationFormats = GetMasterLocations();
        PartialViewLocationFormats = GetViewLocations();
    }

    public string[] GetViewLocations()
    {
        var views = new List<string>();
        views.Add("~/Views/{1}/{0}.cshtml");

        _plugins.ForEach(plugin =>
            views.Add("~/Modules/" + plugin + "/Views/{1}/{0}.cshtml")
        );
        return views.ToArray();
    }

    public string[] GetMasterLocations()
    {
        var masterPages = new List<string>();

        masterPages.Add("~/Views/Shared/{0}.cshtml");

        _plugins.ForEach(plugin =>
            masterPages.Add("~/Modules/" + plugin + "/Views/Shared/{0}.cshtml")
        );

        return masterPages.ToArray();
    }
}

Solve the problem with strongly typed views in the plugins

By using only the above code, we couldn't use strongly typed views in our plugins(modules), because models existed outside of the bin folder. To solve this problem follow the following link.

how about custom route for each individual module? i think each moduleneed to get ref of routetable and global asax should have route interface in which the route interface will look both in module folder and core.

We solved that by defining separate area for each plugin. In each plugin we created a class that inherits from AreaRegistration and by overriding the RegisterArea method we were able to define routes that we wanted to use in the plugins.

i agree with cpoDesign. a sample project would be nice

c# - MEF with MVC 4 or 5 - Pluggable Architecture (2014) - Stack Overf...

c# asp.net .net asp.net-mvc mef
Rectangle 27 6

In MVC : MVC architecture is triangular: the view sends updates to the controller, the controller updates the model, and the view gets updated directly from the model

In Three Tier : A three tier architecture is the client tier never communicates directly with the data tier In a Three-tier model all communication must pass through the middle tier

model view controller - what is the difference between 3 tier architec...

model-view-controller architecture three-tier
Rectangle 27 6

Yes, I think MVC is a different approach than "the" 3-tier architecture that I think you meant here (the architecture where you create mainly 3 projects DAL, BL, and UI). The main idea behind MVC is the separation of concerns between each of its components (Model, View and Controller). The controller is the component responsible for handling user requests, and in most cases it corporates with the "Model" component in order to display the desired view as a response to the user request. The difference between this and the traditional 3-tier architecture, is that the DAL, and the BL are grouped now and named a Model and yes you still need to create these components. What are repositories? Martin Fowler mentions the definition of a repository as "Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects" Repositories are part of your data access layer, they don't access data by themselves, they mediate between the domain and the data mapping entities, and of course they should be placed in your Model folder/project.

Will Linq to SQL be deprecated? NO and the same book states so, also Damien Guard ( a developer at the ADO.NET team) mentioned in one of his blog posts that Linq to SQL will be included in .NET 4.0.

How to interact with EF? As you would with Linq to SQL. Like Linq to SQL, Entity Framework will be your mapping entities, and will reside in the Model project as well. Hope this helps!

asp.net - I need some clarification on the MVC architecture and the th...

asp.net asp.net-mvc linq-to-sql repository-pattern 3-tier
Rectangle 27 2

Hexagonal Architecture has this notion of Adapters, in this case you're adapting from business objects to presentation objects.

asp.net mvc - MVC thin controller architecture - Stack Overflow

asp.net-mvc architecture
Rectangle 27 2

I would go with your second approach and:

  • try do do as much with CSS as you can before resorting to alternate views
  • if alternate views are needed, they should share the same controller, since most of the logic should be identical or very similar
  • make use of partials to share snippets of HTML that are common between views

asp.net mvc 2 - Best MVC architecture for multiple different known bro...

asp.net-mvc-2 architecture
Rectangle 27 17

I consider ASP.Net MVC to be in the presentation layer. The "Model" classes it uses are really View Models, which describe the data structures needed by your views. All of your business logic and data access should remain separate from your MVC models and controllers.

Also, the general "Best Practice" for MVC is to keep the controller code as simple as possible, which usually means introducing some for of application service into your business layer that handles the heavy lifting.

Heh, great minds and all that :)

model view controller - How MVC (ASP.NET MVC) band 3-tier architecture...

asp.net-mvc model-view-controller architecture 3-tier three-tier
Rectangle 27 6

  • You define your resources in various XML files by locale etc.
  • You extend classes like ListActivity, TabActivity and make use of the XML file by inflaters
  • You can create as many classes as you wish for your model
  • A lot of Utils have been already written for you. DatabaseUtils, Html, etc.

MVC architecture in Android - Stack Overflow

android
Rectangle 27 13

MVC is a pattern used to make UI code easier to maintain and test. When the MVC pattern is used a larger portion of the UI code can be unit tested.

Here is a good article which describes the MVC pattern in more detail: http://martinfowler.com/eaaDev/uiArchs.html

3 tier architecture is a pattern used for a completely different reason. It separates the entire application into meaningful "groups": UI, Business Logic, Data Storage.

So 3 tier application refers to all code in the application. The MVC pattern is a pattern used in the UI tier.

For further information you can search the internet and find a gazzilion articles on both subjects.

model view controller - what is the difference between 3 tier architec...

model-view-controller architecture three-tier
Rectangle 27 2

I have trying to work this out and I found a solution that does not involve duplicating code. It's kind of workaround but, in my opinion, it's better than the other proposed solutions.

You have the User Model with all the validation:

public class UserModel
{
    [Required]
    public int Id { get; set; }
    [Required]
    public string Name { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }        
}

You compose the previous model with a new model

public class EditUserModel
{
    public UserModel User { get; set; }

    [Required]
    public string PasswordConfirmation { get; set; }
}

The trick is in the action, you could receive more than one model:

[HtttPost]
public ActionResult UpdateInformation(UserModel user, EditUserModel editUserModel) {
    if (ModelState.IsValid) {
         // copy the inner model to the outer model, workaround here:
         editUserModel.User = user
         // do whatever you want with editUserModel, it has all the needed information
    }
}

In this way the validation works as expected.

In this case how to compare to properties ? e.g. in your case compare Password and PasswordConfirmation with data annotation as OP has asked ?

c# - ASP.NET MVC Architecture : ViewModel by composition, inheritance ...

c# .net asp.net-mvc architecture
Rectangle 27 15

Whoa that was a lot. And I think you have mostly translated Uncle Bob's jargon over to your Spring Java app.

Since architecture is mostly opinion and since your question is sort of asking for one...

There are many different styles of architecture and ... most are overrated. Because most are the same thing: higher cohesion and looser coupling through indirection and abstraction.

What matters MOST (IMHO) are the dependencies. Making lots of small projects as opposed to one giant monolithic project is the best way to get "clean" architecture.

Your most important technology for clean architecture will not be "Spring MVC" technology or "Freemarker" templating language, or another Dr. Dobb's article with diagrams of boxes, hexagons and various other abstract polygons.

Focus on making your code easy to test and write lots of tests.

Beware of focusing too much an bull#%$@# architecture rules. Seriously: if your code is easy to test, easy to change, easy to understand and performs wells then you have a good architecture. There is no 6 weeks to 6 pack abs article to do this (sorry Uncle Bob). It takes experience and time... there is no magic bullet plan.

  • Understand and use some sort of dependency injection (Spring)

Thanks all for the insight, a lot of wise words here. I realize our architecture will very much from itself as we go, but I wanted to get us off the jump as squarely as possible. I may have been over-engineering slightly, or at least tyiong us to the "Clean Architecture" too strictly. As the lines of code pile up, if it is hard to test or dependencies become hard to manage - then it will be time to rethink the architecture.

Not to generalize, make stereotypes, and use hackneyed phrases but there are "hackers" who GSD and there are "thinkers" who write lots of articles... Some are able to do both but I much rather be/listen to Kohsuke, John Resig, Jeff Atwood than a Martin Fowler, Joel Spolesky or Uncle Bob. But thats just me.

java - Maintaining Clean Architecture in Spring MVC with a data-centri...

java spring-mvc model-view-controller mvvm architecture
Rectangle 27 8

However, if both act on the same database, I would make sure that the read model consists entirely of Views so that you can modify entities as needed without breaking the Read code. This has the advantage that you'll need to write less code, but your write model will still consist of a full-fledged entity model rather than just an event store.

What I like to do is use a WCF Data Service for the Read model. This technology (specific to .NET 4.0) builds an OData (= REST + Atom with LINQ support) web service on top of a data model, such as an Entity Framework EDMX.

So, I build a Read model in SQL Server (Views), then build an Entity Framework model from that, then build a WCF Data Service on top of that, in read-only mode. That sounds a lot more complicated than it is, it only takes a few minutes. You don't need to create yet another model, just expose the EDMX as read-only. See also http://msdn.microsoft.com/en-us/library/cc668794.aspx.

The Command service is then just a one-way regular WCF service, the Read service is the WCF Data Service, and your MVC application consumes them both.

Thanks Roy, this makes sense :) Still one question: if you have a WCF service in between the ASP.NET MVC web app and the two models (query and model), do you create additional data contracts (so you need extra mapping) or do you expose the models as data contracts themselves? And would you use a REST-enabled service or plain WCF?

c# - Architecture of an ASP.NET MVC application - Stack Overflow

c# asp.net-mvc asp.net-mvc-3 architecture cqrs