• T4 Templates for Custom ASP.NET Provider

    BuildMotion has a new set of T4 Templates to create a custom ASP.NET Provider. Microsoft provided several providers with the ASP.NET 2.0 release in 2005. You might be familiar with the Membership, Roles, or Profile providers. You can create your own custom providers for your ASP.NET applications. The pattern provides many useful benefits for your application. If you are not familiar with the pattern just google and learn how it can help you.

    These templates use the latest version of T4Toolbox and allow you to create a provider. DOWNLOAD NOW.

    Full story

    Comments (0)

  • T4Toolbox and T4 Templates

    I recently downloaded an update to the T4Toolbox - this utility contains a set of templates and code generators ready for Visual Studio 2010 and 2008. I have a set of templates for generating T-SQL stored procedures, business action classes, T-SQL, and one for creating a new project using the ASP.NET Provider Model.

    Most of the code generation that I doing with these templates is forward-only. I use them to get a jump start or to create a set of classes that I will later implement. As developers, we are always performing some task over and over again. Or sometimes, we have to do a task that is somewhat complex and repeating it manually could introduce errors. Whatever the need, T4Toolbox makes generating code easy and fun. Be sure to download the Visual Studio add-on for a T4 Template Editor by Tangible Engineering.

    I have some T4 Template projects that you can download and use. I will need to update the methods that override the TransformText().

    Full story

    Comments (0)

  • Motion Tracker with Visual Studio 2010 and Entity Framework 4.0

    Visual Studio 2010

    I love the new look. But I'm more excited about the new tools and features of Visual Studio 2010. I just installed Beta 1 on Vista Ultimate - will probably move the Windows 7 as soon as it is out. The other day at work we needed to build a web request tracking tool that could integrate into some custom HttpHandlers. The application tracks web requests and pixels for ad campaigns.

    I didn't need to spend a lot of time on the the software, just needed something that could be built quickly and solved the problem. I decided to use the new Entity Framework 4.0 that is available with .NET 4.0. I was impressed with the ease of the development effort. I created the entities and generated a database using the entity model. I created a website and custom HttpModule that would plug right into the ASP.NET processing pipeline. From start to finish I think it had to be less than an hour for the entire working prototype.

    I thought I'd create another tracking tool and blog about the development along the way. Sometimes, having to document the process along the way is a great way to learn something new.

    Motion Tracker

    This tool will track web requests similar to Google Analytics. The difference in this tool is that it will use and leverage the ASP.NET pipeline, the HttpApplication, HttpContext, and HttpRequest objects. I'll use the information contained in these objects to track the web requests. I'll also add some objects to track the Session information for a user. And I'd like to provide a mechanism to track custom events using a tagging structure like GA - track special actions, web events (e.g. clicks, downloads, result-in-list, item-viewed, etc.), and e-commerce transactions.

    Since, I'll be using ASP.NET objects, I might even consider using some of the information in the HttpResponse if applicable. This already sounds like a heavy duty application. But I think that the new tools in Visual Studio 2010 and the Entity Framework 4.0 will make this work easier to implement and develop. And since, we are going all out, why don't we add some admin screens. We could create accounts and Motion Tracker instances for different web sites. Then we'll definitely need some reports for the end-user and administrators of the application.

    Motion Tracker - Just another Analytics Tool?

    There is a lot of software that is developed and deployed over and over again. Changes are made and continue to be made. Many time the changes are driven by perceived notions. How can you quantify the results and performance of software? How do you know that the changes improved the software or the user experience - you need to be able to quantify. Most programmers have worked for the company where the owner or the president seems to have uncanny ability to do his job and also knows how to do yours too! Amazing, the decisions are made, we program them, we deploy them, we changes them back, we do this over and over again. It is insanity.

    You should be able to quantify the performance and the usage of an application. Changes should be monitored and reverted back if the change doesn't improve the experience or performance. Most modern web analytic or web trend tools do not have the level of detail or the ability to plug into existing application for deeper analysis and diagnostic integration. There is also a need to be able to analyze the information to make informed decisions. Is there already a tool out there like this one - not exactly? There are plenty of web analytic tools out there. I think there is a niche for this kind of tool to have a deeper integration with the software and website. Can Google Analytics track authenticated users and provide the time spent per user on pages and what actions were performed? Can it integrate with cross-market analytics and provide comparison models as to the metrics of one website to another in a similar market? Web 2.0 features along with AJAX has brought about Rich Internet Applications (RIA) - tracking analytics with RIA applications is a different game. Perhaps this tool, Motion Tracker, can provide some solutions to the problems just outlined.

    Tool Box

    I'll list some of the tools that I will be using to develop this application

    • Visual Studio 2010 with .NET 4.0
    • SQL Server 2008 Express Edition
    • Microsoft Enterprise Application Blocks 4.0
    • Build Motion Application Framework
    • Web Control Suite: Telerik, ComponentArt, or Infragistics
    • JQuery
    • Continuous Integration Tool (TBD)
    • Unit Testing Tool (TBD).

    Architectural Approach

    The application will be developed using typical tiers and layers. This will allow the application to be developed using an enterprise approach. The performance and scalability of the application is important because it shouldn't interfere the normal processing of the application it is supporting. We will take a domain-driven design approach and create entities that map to the business of the application at hand. We will employ repository and adaptor patterns, along with the ASP.NET Provider Model pattern to implement the vertical services of the application.

     

    Full story

    Comments (0)

  • .NET 4.0 Entity Framework - Is it for real?

    The purpose of this document is to question how the .NET 4.0 Entity Framework will handle POCOs and Persistent-Ignorant objects. These concepts are not new to enterprise and domain-driven developers. In fact, these concepts precede that of .NET and C#. I will not provide a discussion on these topics because there are many excellent guides, books, and other resources available.

    • ·         Technology: Microsoft .NET 4.0 Entity Framework
    • ·         Tools: Visual Studio 2010
    • ·         Database: SQL Server 2008 or SQL Server 2008 Express Edition

    In this discussion, I will raise some concerns about the Entity Framework; and implementation details that the Entity Framework should allow. The Entity Framework is really a dual-edge sword. First, it provides entity classes to have extended base functionality (e.g. change tracking, unit of work, deferred or “lazy” loading). The other edge is the ability to persist and to retrieve entity items from the data store. We should also throw in some domain-driven design patterns like repository, adaptor – and even add the provider-model pattern. How can we make all of this work together?

    Just a thought, if you are a home builder or contractor – there are always new tools and products released promising to make the job easier. When tools are being selected, they are usually selected for the types of jobs or tasks that the builder routinely does. Most home builders rarely need a crane to perform day-to-day tasks. Nor do they use a simple hand shovel to dig a foundation for a new home. Typically, the builder owns and purchases the tools that he uses most. The other tools (e.g. cranes and bull-dozers) are rented or contracted out to another company. I wonder what category the new Entity Framework fits in? This is an important question for developers. We cannot just choose to the Entity Framework because it is new and part of .NET 4.0; or that Visual Studio 2010 provides nice visual tools to work with. Really, what kind of applications is the Entity Framework really suited for? Is it for simple utility applications or small web applications with a limited number of users? Can it be adapted or incorporated into enterprise-level applications and ease the development effort? What about performance? If the application requires a high-level of performance and/or scalability – would the new Entity Framework be a good choice. There are a lot of questions here. The answers will come in the next few months and years.

    This is really where it begins. The domain model provides the items that will be used within the application. The names, types, and relationships between the domain items are very important and should be well thought out. This process requires a combination of right and left brain activity. It is not just a science but also an art that can be crafted and improved upon over time. The domain models you create now would probably be different from ones you would create years from now. Depending on your skill-level, creativity, years of experience – the models you create today will only be as good as you are today. Years from now, we would hope that the model for the domain currently at hand would be improved or better based on your heightened skills and creativity.

    The domain model is a set of classes that map to the domain of the application. It appears that with the current Entity Framework that there is a clear dependency on the model and the schema of the database. For example, with POCO and persistent ignorance models – the entity classes are simple. However, in order for it to work with the Entity Framework, the property names have to match to the column names in the database tables. Should the model look like the database schema? In fact with the new Entity Framework, you can generate your database schema/script and create a database from the model. So, another question, are the classes created for the domain a relational model or an object model? Inheritance rules. Design by interface. The common techniques should still be used by domain-driven developers who are creating class hierarchies that are used in the application domain.

    What we need is for the Entity Framework to provide mapping capabilities so that the impedance mismatch discussed in domain-driven design and POCO development can be addressed. Does the Entity Framework and the tools (e.g. Visual Studio 2010) allow for management and development of the mapping. Should the names of the properties in a domain object use the same names in the database schema? By default, this is a requirement when using POCOs with the Entity Framework. In most real-world and enterprise applications this will certainly not work. I do not want to use the names that the DBA used to create the database schema as the names for me to use with my entity classes. I image that you can decorate properties in domain classes with attributes that allow mapping to the correct item in the model. However, is the POCO still a plain-old-CLR-object? It now contains mapping information. Our next item of discussion please.

    At the core of making all of this work is the mapping between an entity and the data store. Something magical happens in the middle that allows you to create, modify and save changes, and to retrieve single or collections of entity items from the data store. This leads to another question/requirement about the Entity Framework. It should allow you to connect to and to retrieve information from different kinds of data stores.

    The solution is in how the information contained in an entity is mapped to a database schema. This really has been at the heart of ORM solutions for almost a decade now. There are many commercial and home-grown solutions that have been developed. How they perform this mapping varies. Configuration files, code generation based on database schemas, data adaptor patterns and other technical solutions provide the mechanism to make the magic happen.

    There is a saying, “that the best developers are lazy.” I don’t know who came up with this phrase – over the years I am beginning to doubt this explanation. Programmers or developers that don’t like to write code. Maybe we just don’t like to write boring code – we want to write the sexy code that performs some great logic. I guess sending information or retrieving it from a database is not very sexy or exciting code to write. However, it is probably one of the more important features of an application. It appears that some delegate this task to code generators or other tools and processes to lighten the load. I hope that the Entity Framework is one of those tools. Some may take the approach of code generation for some of the code (e.g. scaffolding or infrastructure) that provides a jump-start in the development process. Some tools provide a round-trip approach and everything is code-generated and cannot be modified because regeneration will overwrite the modified code.

    This raises another good question about the effect of changes to the schema and/or the entity model has on the Entity Framework. Is there a strong enough dependency that when one changes that the other must be modified also? Should there be an abstraction of the persistence layer and the mapping between the data schema and the domain model? I think so. If the domain model entities look like tables in the database and are tightly coupled to the mapping/persistence layer – is this a good thing.

    I have found that many times when I develop entity models that the items sometimes look very similar to the database tables. It is an interesting development approach to have the developers with (2) different skill-sets to develop each layer. I think the relational and object-oriented approaches that each developer takes will provide two very distinct solutions. Thus the need to map. The mapping has to occur somewhere in the application. Also, depending on the performance and scalability requirements of the application – how this is done and what technologies used may be very important. I would suggest that prototypes are developed to load test each solution to determine which provides the best performance and/or allows for the greatest scalability. You really need to understand how the application will be used early to be able to make such decisions. This goes back to the principle that we just don’t use a tool because it is new and there is a lot of attention given to it. Think of the tools and technologies that have stood the test of time. Many of these are simple and provide elegant solutions. There is even a bigger list of tools, frameworks, and other technology rejects that are no longer used or just simply forgotten. They may have served a purpose for a time – but the test of longevity lies in the simplicity and elegance of what the tools provides. For example, you do not hear Microsoft talking about BizTalk too much these days? This tool served its purpose – but does it provide the same value as it did back in the day. I haven’t heard of the new BizTalk 2010 with Visual Studio integration!

    The new tools may come and go. However, there is still an art to hand-crafted software using proven and tested techniques, patterns, and tools. We could spend all of our time learning the new tools and how the work – or even better what we need to do to create workarounds for things that they cannot do yet, but are promised in an upcoming release.

    Full story

    Comments (0)

  • Build Motion - Application Frameworks

    Why an Application Framework?

    There are many reasons to consider using an Application Framework for softwaredevelopment. Take the following survey:

    • You currently have to maintain code that makes you want to take a shower - you feel a little dirty?
    • The business logic and rules are in the ASP.NET code-behind or in stored procedures or both? Or you do not know where they are.
    • There isn't any consistency in managing exceptions or logging them?
    • You have methods in your code that are more than 1000 lines of code?
    • Your application has T-SQL embedded in the code?
    • You want to develop clean, maintainable, and beautiful software - that works and enjoy doing it.

    If you answered yes to any of these questions, you should be using an application framework. Which one do you use? Do you purchase one? Are there reliable and good open source frameworks available? Should you develop your own? The answer depends - and it also varies depending on your needs, requirements, and complexity of business domain, time-to-market, or other concerns. Therefore, you may need to be familiar with more than one and also know when you may need to create your own.

    This is the first post in a series that will provide an outline of elements that make up a .NET Business Object Framework. The framework will leverage best practices from existing .NET application and entity frameworks. It is the goal to provide a reliable and easy to use framework to allow developers to focus on the business problem and domain without the distraction of plumbing code.

    During the last 5 years, I have been able to use open source and custom application frameworks to develop .NET applications. The main goal of these frameworks is to eliminate the need to write repetitive code and to reuse common elements. What I have found to be the case is that none of the existing products available the silver bullet developers need and want. I do not believe that there is an application framework that can definitely say it is the silver bullet. As developers, we need to understand that the purpose of a framework is to provide consistency and reusability of the framework elements. Software developed in this manner is much easier to explain and to maintain. It should increase developer productivity over time - because familiarity of the framework will allow the developer to spend more time providing a business domain solution.

    I would encourage business application developers to become familiar with more than one application framework. There are many open source frameworks available for .NET and Java. Study the code. Identify the common elements. Learn how they work together - and especially identify how the framework elements enable rapid application development. Each framework will have its strengths and weaknesses. Some might focus on code generation and data persistence. Some frameworks focus on entity objects. There are different implementations of layers or tiers within the application. Some frameworks may not give consideration to tiers/layers.

    There is not a single application framework that contains every element that is required for every application. Using the construction of a building is a good example in this case. In most cases there is not a single supplier of materials for the construction of a building. As the project progresses, different kinds of materials are required. We wouldn't expect the supplier that provided the concrete to also supply the materials for the ventilation or electrical systems. So, we wouldn't expect that a single application framework to provide all elements for the construction of a software project. However, the application framework should be flexible enough to allow for other elements to be plugged into the framework seamlessly. So the end result of the software is that there is a comprehensive application that is consistent in construction and allows for easy maintenance.

    Here is the outline of common elements that should be considered when developing, choosing, or using an application framework for business software. Common Elements:

    Architecture

    Does the framework allow for different architectural concerns. Is it compatible with web services? Can it be deployed in separate physical tiers? Consider how the framework will allow your application to scale or not scale. Your application may not require scalability as a concern.

    • Layers
    • Tiers
    • Vertical Services
    • Service APIs
    • Scalability

    Security

    Learn how the framework handles security concerns. Is it flexible enough to use your security? Does it work with other security mechanisms (e.g. Microsoft Membership and Role Providers)?

    • Authorization
    • Authentication
    • Permissions
    • Membership
    • Roles
    • Encryption
    • Security Context

    Business Domain Implementation

    The framework should not hinder your business domain implementation. Is it easy to implement business logic?

    • Domain Driven Design
    • Business Actions
    • Business Service
    • Business Repository

    Business Rules

    Some frameworks contain APIs for processing and handling business rules. Most applications require business rule processing at some level - using a framework or a BRE (business rule engine) that can plug into the framework is a nice feature to have. The Build Motion Framework contains a business rule processing engine that allows for simple and composite rules. It also contains a library of common data and validation rules that can be used. The Build Motion Rule and Validation Engine has an API that allows for the creation of custom rules to be reused throughout an application

    • Business Rule Engine
    • Common Rules
    • Rule Processing
    • Rule Violation Notification

    Exception Handling and Logging

    Your application would not be complete without being able to log exceptions or other information. This can be as simple as logging to an event log or text file. There are several tools out there for .NET - I prefer the Microsoft Enterprise Application Block for Logging. It is easy to use and configure and allows for customization on where the information is logged to. The Build Motion framework logs the information to a Log Database.

    • Exception Logging and Publishing
    • Custom Exceptions
    • Unhandled Exceptions

    KPI Logging

    • Capturing KPI data
    • Logging KPI data
    • Reporting KPIs

    Entity Objects or Data Objects:

    Business applications use and consume data. Handling this data in the most efficient manner allows the application to perform better. The data should speak to the domain of the application. Build Motion uses Domain-Driven-Design to create data objects that map to your business. The Build Motion Framework contains Entity patterns or simple POCO/DTO-like objects. You choose.

    • Data Transfer Objects or POCOs
    • Entity Collections
    • Entity State Tracking
    • Property Changed Notification

    Data Persistence

    Most frameworks will work well with a single database. How about many? What if your datastore is not a database - but a web service? Or, how do handle when your application requires access to multiple databases of different types? The Build Motion Framework uses patterns that allow an application to use multiple data stores. Modern applications use 3rd-party solutions like Sales Force, Credit Card gatewways, and web services. Does your framework allow for this type of configuration if you need it?

    • Data Providers
    • Data Adaptors
    • Configuration
    • Business Service

    Configuration

    • Connection Strings
    • Environment Settings (Development, Stage, Production)
    • Providers (Exception Handling, Logging, Encryption)

    Process

    Some of the items listed below are not really part of a framework. However, the frameworks you decide to use should allow you to continue using best practices like: unit testing and continuous integration. If the framework you are considering doesn't allow for following a good process - you might ask yourself if you are really making the right framework decision.

    • Unit Testing
    • Continuous Integration
    • Code Documentation
    • Code Analysis
    • Performance Testing
    • UI Testing
    • SDLC

    Full story

    Comments (0)

  • T4 Templates for Stored Procedures

    Generating Code or Stored Procedures

    There are a lot of choices for generating .NET code and T-SQL for SQL Server stored procedures. I have used CodeSmith, MyGeneration, NetTiers. All of them are fine tools. One of the nice features about these tools is the ability to use and create templates. One of the disadvantages is that you have to use a proprietary scripting or syntax to create these templates (e.g. CodeSmith and NetTiers). 

    Therefore, I was intrigued with the ability to use C# syntax with the T4 templates. Also there was a nice advantage to use Visual Studio to work with the templates and running the process. I had a current need to create common stored procedures for my database tables. I’ve used various tools before – but I wanted to give T4 Templates a shot. I borrowed the base templates used in a sample from Oleg Sych’s blog using the T4 Toolbox assembly as well. This was a great start to using T4 Templates - however the Select template(s) were not implemented.

    My solution contains a set of templates for each of the stored procedure types that will be created using the data schema from the database tables. Download files here.

    • Delete
    • Insert
    • SelectAll
    • SelectByForeignKeys
    • SelectByForeignKey
    • Update

    I started with the solution from Oleg’s blog and modified the solution to support the different templates and writing each type out to a separate file. I also added a new template that creates the OSQL command line statements to execute from a command prompt using OSQL. This will add the new stored procedure objects to the specified database.

    To Use the Templates

    You will need to update the connection string in the StoredProcedureGenerator.tt file. To generate the stored procedures, you need to right-click the RunGenerator.tt file within Visual Studio and select the “Run Custom Tool” option. This will begin the transformation process.

    Full story

    Comments (0)

  • // alert("Hello World");

    I am Matt Vaughn and this is my Build Motion blog. I've been developing .NET solutions since the original beta release. I've spent the last several years building and using custom application frameworks. I love tools, process, and patterns. I believe that high-quality software is achievable even within a short time line to market - however, you need the right resources (e.g. people), the right tools, and the right process.

    These combined create a huge momentum and synergy within a team. Using proven structures and patterns give stability and reliability to our software. The process provides consistency. The outcome should be maintainable and extensible software that is robust and high performant (performant by the way is not an accepted word, but it sounds nice).

    I will be blogging about:

    • .NET and developer tools
    • Process for developers and teams
    • Architecture and Patterns

    Full story

    Comments (0)