Giter Site home page Giter Site logo

catfactory's Introduction

CatFactory ==^^==

What Is CatFactory?

CatFactory is a scaffolding engine for .NET Core built with C#.

How does it Works?

The concept behind CatFactory is to import an existing database from SQL Server instance and then to scaffold a target technology.

We can also replace the database from SQL Server instance with an in-memory database.

The flow to import an existing database is:

  1. Create Database Factory
  2. Import Database
  3. Create instance of Project (Entity Framework Core, Dapper, etc)
  4. Build Features (One feature per schema)
  5. Scaffold objects, these methods read all objects from database and create instances for code builders

Currently, the following technologies are supported:

This package is the core for child packages, additional packages have created with this naming convention: CatFactory.PackageName.

  • CatFactory.SqlServer
  • CatFactory.PostgreSql
  • CatFactory.NetCore
  • CatFactory.EntityFrameworkCore
  • CatFactory.AspNetCore
  • CatFactory.Dapper

Donation

You can make a donation via PayPal using this link: paypal

Thanks for your help! ==^^==

Roadmap

There will be a lot of improvements for CatFactory on road:

  • Scaffolding Services Layer
  • Dapper Integration for ASP.NET Core
  • MD files
  • Scaffolding C# Client for ASP.NET Web API
  • Scaffolding Unit Tests for ASP.NET Core
  • Scaffolding Integration Tests for ASP.NET Core
  • Scaffolding Angular

Concepts behind CatFactory

Database Type
Project Selection
Event Handlers to Scaffold
Database Object Model
Import Bag

Read more on: Concepts behind CatFactory

Packages

CatFactory
CatFactory.SqlServer
CatFactory.PostgreSql
CatFactory.NetCore
CatFactory.EntityFrameworkCore
CatFactory.AspNetCore
CatFactory.Dapper
CatFactory.TypeScript

Read more on: Packages Features Chart

History

In 2005 year, I was on my college days and I worked on my final project that included a lot of tables, for those days C# didn't have automatic properties also I worked on store procedures that included a lot of columns, I thought if there was a way to generate all that code because it was repetitive and I wasted time in wrote a lot of code.

In 2006 beggining I've worked for a company and I worked in a prototype to generate code but I didn't have experience and I was a junior developer, so I developed a version in WebForms that didn't allow to save the structure ha,ha,ha that project it was my first project in C# because I came from VB world but I bought a book about Web Services in DotNet and that book used C# code, that was new for me but it got me a very important idea, learn C# and I wrote all first code generation form in C#.

Later, there was a prototype of Entity for SQL, the grandfather of entity framework and I develop a simple ORM because I had table class and other classes such as Column, so after of reviewed Entity for SQL I decided to add the logic to read database and provide a simple way to read the database also of code generation.

In 2008 I built the first ORM based on my code generation engine, in that time it was called F4N1, I worked on an ORM must endure different databases engines such as SQL Server, Sybase and Oracle; so I generated a lot of classes with that engine, for that time the automated unit tests did not exist, I had a webform page that generated that code ha,ha,ha I know it was ugly and crappy but in that time that was my knowledge allowed me.

In 2011 I worked on a demo for a person that worked in his company and that person used another tool for code generation, so my code generation engine wasn't use for his work.

In 2012 I worked for a company needed to rebuilt all system with new technologies (ASP.NET MVC and Entity Framework) so I invested time about MVC and EF learning but as usual, there isn't time for that ha,ha,ha and again my code generation it wasn't considered for that upgrade =(

In 2014, I thought to make a nuget package to my code generation but in those days I didn't have the focus to accomplish that feature and always I used my code generation as a private tool, in some cases I shared my tool with some coworkers to generate code and reduce the time for code writing.

In 2016, I decided to create a nuget package and integrates with EF Core, using all experience from 10 years ago :D Please remember that from the beginning I was continuing improve the way of code generation, my first code was a crap but with the timeline I've improved the design and naming for objects.

Why I named CatFactory? It was I had a cat, her name was Mindy and that cat had manny kittens (sons), so the basic idea it was the code generation engine generates the code as fast Mindy provided kittens ha,ha,ha

Source picture for CatFactory concept

Trivia

  • The name for this framework it was F4N1 before than CatFactory
  • Framework's name is related to kitties
  • Import logic uses sp_help sp to retrieve the database object's definition, I learned about this in my database course at college
  • Load mapping for entities with MEF, it's inspired in "OdeToCode" (Scott Allen) article for Entity Framework 6.x
  • Expose all settings in one class inside of project's definition is inspired on DevExpress settings for Web controls (Web Forms)
  • There are three alpha versions for CatFactory as reference for Street Fighter Alpha fighting game.
  • There will be two beta versions for CatFactory: Sun and Moon as reference for characters from The King of Fighters game: Kusanagi Kyo and Yagami Iori.

Quick Starts

Scaffolding Dapper with CatFactory

Scaffolding View Models with CatFactory

Scaffolding Entity Framework Core 2 with CatFactory

Scaffolding ASP.NET Core 2 with CatFactory

Scaffolding TypeScript with CatFactory

catfactory's People

Contributors

david-ben-mesecke avatar ewmccarty avatar hherzl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

catfactory's Issues

Refactory Database class definition

Refactory CatFactory.ObjectRelationalMapping.Database class definition, this definition must have properties for the following database objects:

  1. Stored procedures
  2. Sequences
  3. Scalar functions
  4. Table functions

All these members must be removed from CatFactory.SqlServer.SqlServerDatabase class definition.

Bug: error @ databaseFactory.Import() when DB is on Azure

When trying scaffolding from SQL hosted on azure, I got this exception. I created a new, empty DB and added a single table but the error was the same...neither did logging with debug provide more info.

Code:

        public static void Main(string[] args)
        {
            Scaffold();
        }

        public static void Scaffold()
        {
            var serilog = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.Console()
                .CreateLogger();

            var loggerFactory = new LoggerFactory()
                .AddSerilog(serilog);

            Microsoft.Extensions.Logging.ILogger logger = loggerFactory.CreateLogger<SqlServerDatabaseFactory>();
            
            // Create database factory
            var databaseFactory = new SqlServerDatabaseFactory(logger)
            {
                DatabaseImportSettings = new DatabaseImportSettings
                {
                    ConnectionString = "Server=tcp:Xxx.database.windows.net,1433;Initial Catalog=azure-test-db;User Id=Xxx;Password=Xxx;",
                    ImportTables = true
                }
            };
            
            // Import database
            var database = databaseFactory.Import();

Exception:

System.InvalidCastException
  HResult=0x80004002
  Message=Object cannot be cast from DBNull to other types.
  Source=System.Private.CoreLib
  StackTrace:
   at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider)
   at System.Convert.ToInt32(Object value)
   at CatFactory.SqlServer.SqlServerDatabaseFactory.SetIdentity(View view, IDictionary`2 dictionary)
   at CatFactory.SqlServer.SqlServerDatabaseFactory.<GetViewsAsync>d__41.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at CatFactory.SqlServer.SqlServerDatabaseFactory.<ImportAsync>d__19.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at CatFactory.SqlServer.SqlServerDatabaseFactory.Import()
   at Xxx.DbContext.Program.Scaffold() in C:\$_Work\Xxx.DbContext\Program.cs:line 36
   at Xxx.DbContext.Program.Main(String[] args) in C:\$_Work\Xxx.DbContext\Program.cs:line 13

  This exception was originally thrown at this call stack:
    [External Code]
    Xxx.DbContext.Program.Scaffold() in Program.cs
    Xxx.DbContext.Program.Main(string[]) in Program.cs	

Add positional flag in property definition

In order to scaffold a record with positional syntax, the properties need a flag to set positional declaration.

Example:

public record Bar(Guid Id, int X, int Y, int Z);

Praise and questions and then some :)

Only had time for a short read through yet but from what I can see, I can scaffold everything from the data access layer and repositories via business objects to the web.api controllers based on my data models, even typescript? wow! I currently use TypewriterX to scaffold models and services for angular from my data models and API controllers, respectively, that amazing success has given me the urge to go even further and that is how I ended up here.

From the short read through it seams its easy to learn your templating DSL and a quick look at your GitHub repository tells me you are planning full angular support as well. I do not have any questions yet, I am sure I will when I get to it, but I do wish to add some praise and thanks for this scaffolding framework. great job!!! Thumbs Up | ๐Ÿ‘ Thumbs Up | ๐Ÿ‘ Thumbs Up | ๐Ÿ‘

Ops, there came the first question to mind, is there any get started video to be found yet? Cool | ๐Ÿ†’

Also, I checked a bit further, does it work already?

PS: I by the way tried to send you a pull request since I added public GetKebabCase and private HasUpper and HasLower methods to the CatFactory.NamingConvention class as well as unit tests to check if they work as well as fixed the GetSnakeCase method so it would also split on uppercase and added additional unit tests for it. I think I failed though, never used git as source control before, only TFS and Azure DevOps... Please advice...

Cheers!

Could I contact to U

It is possible to contact to U ?
I have Idea about ef core!

Developing custom migrator uppon Ef core Migration tools!
Already possible to generate Migrations and apply it!
But need Yore opinon!

It very Enterprise Idea !
Have build js gui on vue!

image

Add import bag property in database objects

Add import bag property in the following database objects:

  1. ScalarFunction
  2. TableFunction
  3. StoredProcedure
  4. Sequence

The property must have the following signature:

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private dynamic m_importBag;

/// <summary>
/// Gets or sets the extension data for import
/// </summary>
[XmlIgnore]
public dynamic ImportBag
{
	get => m_importBag ??= new ExpandoObject();
	set => m_importBag = value;
}

This change will allow add extended properties in import database feature.

Fix definition for ExtendedProperties in ImportBag property in Column class

In order to use AddColumnForTables extension method, there is a hack:

dynamic importBag = new ExpandoObject();

importBag.ExtendedProperties = new List<ExtendedProperty>();

db.AddColumnForTables(new Column { Name = "Active", Type = "bit", ImportBag = importBag });
db.AddColumnForTables(new Column { Name = "CreationUser", Type = "nvarchar", Length = 50, ImportBag = importBag });
db.AddColumnForTables(new Column { Name = "CreationDateTime", Type = "datetime", ImportBag = importBag });
db.AddColumnForTables(new Column { Name = "LastUpdateUser", Type = "nvarchar", Length = 50, Nullable = true, ImportBag = importBag });
db.AddColumnForTables(new Column { Name = "LastUpdateDateTime", Type = "datetime", Nullable = true, ImportBag = importBag });
db.AddColumnForTables(new Column { Name = "Version", Type = "rowversion", Nullable = true, ImportBag = importBag });

This is a suggested fix for ImportBag property definition in Column class:

[XmlIgnore]
public dynamic ImportBag
{
	get
	{
		if (m_importBag == null)
		{
			m_importBag = new ExpandoObject();
			m_importBag.ExtendedProperties = new List<ExtendedProperty>();
		}
		
		return m_importBag;
	}
	set
	{
		m_importBag = value;
	}
}

Migrate to .NET Core 3.1

Since 2.1 and 3.1 versions for .NET Core are in LTS, CatFactory must migrated to .NET Core 3.1

Also, the following packages need update:

  • Microsoft.Extensions.DependencyInjection
  • Microsoft.Extensions.Logging
  • Microsoft.Extensions.Logging.Console

OnLineStore

Where is the source for the OnLineStore database?

Add Fluent API for Class Definition

Add extension methods to allow reduce syntax on create class definitions.

Proposed design:

var classDefinition = ClassDefinition
 .New(AccessModifier.Public, "EmployeeController", "ShanghaiCat.API.Controllers", baseClass: "ControllerBase")
 .IsPartial()
 .AddDefaultCtor()
;

Output:

namespace ShanghaiCat.API.Controllers
{
	public partial class EmployeeController : ControllerBase
	{
		public EmployeeController()
		{
		}
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.