Why and when to create a project library in .NET?

Why and when to create a project library in .NET?

I’ve interacted with many different business systems that have their solution broken up differently in respect to the number of project libraries.  And I’ve discussed this with developers and it seems everyone has their own opinion.  I’ve thought a lot about this and I’m to discuss my opinion.

Here are some reasons that I can think of why you may want to create a new project library:

  • For organization purposes, reduce complexity, Single Responsibility Principle, encapsulation and decoupling code. 
    • This is useful if you want to keep a library self-contained easy to comprehend.  There is less code to have to comprehend at once.
    • You can hide code from other systems from misuse.
  • Limiting amount of deployed code.  Limit the size of libraries. 
    • This is useful if you want to limit the size of the binary that is deployed and executed. 
  • For limiting dependencies.
    • This helps make it easier to modify code.  Less dependencies me less code will be impacted by changes.
  • Limiting references
    • This is a negative reason to create a project.  The more projects you have the more likely you will have to add duplicate references.
  • For security purposes.
    • This is useful if you want to secure code from just anyone accessing it.
  • For critical code purposes.
    • This is useful if you want code to be performant and not be susceptible to bugs from other code changes.
  • For functional purpose such as specific layer and for controlling layer access.       
    • Makes it easier to switch out layers and layer specific frameworks.
    • Reduces framework dependencies.
  • For avoiding merge conflicts.
    • With many developers working on a code base, the more libraries help reduce merge conflicts.
  • For avoiding unnecessary builds and limiting change impact.
    • More libraries means that not everything needs to be built .
    • In visual studio, too many projects can lead to build order issues and poor build performance.
    • If something not changing then it might mean a lower probability of introducing bugs.
  • For common, reusable code that rarely changes.
    • This is useful for functionality that you rarely need to review and look it. 
    • The more code like this the better.  Projects like this do not necessarily need to be in the solution but can be referenced as DLL.

Here are some ways I’ve seen business and data libraries organized

1.       One BLL, One DAL

  • This one leads to too much tightly coupled code.  It fails the single responsibility pattern.  There is no encapsulation.  It mostly doesn’t limit dependencies.  It limits the ORM framework to DAL.
  • Lowers Project/DLL count

2.       Multiple BLL and DAL for each domain

  • Limits dependencies though DAL is available to all.  It reduces coupling of domain and layers.
  • Increases Project/DLL count.

3.       Multiple domain with both BLL and DAL included

  • It reduces coupling of domain.
  • It limits dependencies except EF is available to business.
  • It encapsulates DAL from external access.
  • Less Projects/DLLS than multiple DLL solution.

I tend to not like #1 because everything is accessible to everything.  The is no access control in place.

Number 2 is better than #1.  The only thing is I don’t see too much benefit in having the DAL broken out.  Maybe there is some Unit Testing or analytic benefit.  With #2 there is also an increase in the number of DLLS.  This style should limit the number of DLLS to a few high level areas.

I personally lean towards #3 “Multiple domain with both BLL and DAL included” because it limits access to code.  And the amount of code can be reduced such that it is easier to comprehend.  I think it is a good comprise between #1 and #2.  I tend to think in terms of how distributed systems are organized and this seems to line up with that. 

In general, I want projects where I can control access to the code.  I want code that is easy to maintain, which doesn’t have a ton of dependencies that I have to review and comprehend before making a change.  I want to be able to write code and forget about it as other code uses it. 

At the same time I don’t want a lot of libraries in a solution.  I want quick build and deploy times and small DLL sizes.

I may follow this up with a Part 2 discussion.





Useful GitHub resources

This was a good introduction into GitHub on Microsoft Virtual Academy.  The course name is GitHub for Windows Users


Command line Cheatsheet


Good documentation


Good information on getting involved in open resource


Book List

Soft Skills & Leadership

  • Soft Skills: The software developer’s life manual, by John Sonmez
  • The Five Dysfunctions of a Team: A Leadership Fable, by Patrick Lencioni

Software Architecture

  • Just Enough Software Architecture – A Risk Driven Approach, by George Fairbanks
  • Designing Software Architectures: A Practical Approach, by Rick Kazeman
  • Clean Architecture: A Craftsman’s Guide to Software Structure and Design, by Robert Martin
  • Documenting Software Architectures: Views and Beyond, by Paul Clements
  • Software Architecture in Practice, by Len Bass
  • Patterns of Enterprise Application Architecture, by Martin Fowler
  • Software Architecture for Developers, by Simon Brown

Software Design

  • Refactoring: Improving the Design of Existing Code, by Martin Fowler and others
  • Refactoring to Patterns, by Joshua Kerievsky
  • Pattern-Oriented Software Architecture, multiple volumes, by Frank Buschmann
  • Design Patterns: Elements of Reusable Object-Oriented Software, by Erich Gamma
  • The Clean Coder: A Code of Conduct for Professional Programmers, by Robert Martin
  • Code Complete: A Practical Handbook of Software Construction, by Steve McConnell
  • Agile Principles, Patterns, and Practices in C#, by Robert Martin
  • Clean Code: A Handbook of Agile Software Craftsmanship, by Robert Martin


  • Agile Software Requirements: Lean Requirements Practices for Teams, Programs, and the Enterprise, by Dean Leffingwell

Language Specific


  • Professional ASP.NET MVC 5, by Jon Galloway
  • Pro ASP.NET MVC 5, by Adam Freeman


  • Programming WCF Services, by Michael Montgomery

C#, .NET

  • C# 7.0 In a Nutshell, multiple version of C#, by Joseph Albahari
  • Pro Asynchronous Programming with .NET, by Richard Blewett
  • Dependency Injection in .NET, by Mark Seemann


  • Secrets of the JavaScript Ninja, by John Resig
  • Angular 2 Development with TypeScript, by Yakov Fain

SQL Server

  • SQL Server Internals, by Kalen Delaney


  • Plural Sight
  • Safari Books Online




When it comes to reading books, I’m terrible at it.  I rarely finish a book.  I usually get through a third of a book and I’m distracted by another book and start it.  It’s also difficult for me to remember what I read and technical things take me longer to comprehend so I try reading at a slower pace to make things stick better.  All that being said, I do think I can recognize a good book.  I am more attracted to books that I believe will stand the test of time or at least be useful for a few years.  And I tend to prefer good authors and experts in the field.

Basic for setting up a new angular application

These are the basic steps involved in creating a new project in Angular 2.

Step 1 Initial setup

Install Node

Install TypeScript

Run the node command npm install -g typescript

Step 2 Create a new project

Here are 2 options from many for creating the new project

If using ASP.NET

  1. If you are using ASP.NET then there are SPA templates that can be used.  See https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/
  2. Install templates with command dotnet new –install Microsoft.AspNetCore.SpaTemplates::* 
  3. Created new application
  4. Create empty folder and run node command dotnet new angular

If using Angular CLI

  1. Install Angular CLI – starter project from scratch npm install -g @angular/cli
  2. Be sure to be in the project’s parent folder
  3. Run command ng new ApplicationName
  4. >This will create a new folder with the name and it will install all the dependencies
  5. https://scotch.io/tutorials/use-the-angular-cli-for-faster-angular-2-projects
  6.   https://cli.angular.io/

Step 3 Install dependencies

npm install

Step 4 Build

ng Build

Step 5 Run

Run this command: npm start – same as npm run prod, ng serve, ng serve –e dev

Stop is ctrl-c


I had a task where I needed to add basic authorization to a soap call and I found that I couldn’t set the network credentials nor the authorization header.  In order to do this you have to create another class that inherits the proxy class and then override the GetWebRequest method.  Here is sample code:

using System;
using System.Net;
using System.Text;

namespace MyNamespace
    public class MyProxyOverride : TheProxy
        string _url = null;
        string _username = null;
        string _password = null;

        public MyProxyOverride(string url, string userName, string password)
            _url = url;
            _username = userName;
            _password = password;

        protected override System.Net.WebRequest GetWebRequest(Uri uri)
            var request = (HttpWebRequest)base.GetWebRequest(new Uri(_url));
            var netCredential = new NetworkCredential(_username, m__password);
            var networkCredentials = netCredential.GetCredential(new Uri(_url), "Basic");

            if (networkCredentials != null)
                byte[] credentialBuffer = new UTF8Encoding().GetBytes(
                networkCredentials.UserName + ":" +
                request.Headers["Authorization"] =
                "Basic " + Convert.ToBase64String(credentialBuffer);
                throw new ApplicationException("Missing authentication information.");
            return request;



Basic React Component Structure

Here is some sample code to create a basic react component


<div>import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
return (
<HelloWorld />

class HelloWorld extends React.Component {
return (


<h2>Hello World</h2>



export default App</div>

<div>//or ReactDOM.render(<App />, document.getElementById('app'));</div>