I want to generate boiler plate code in my repository pattern project - .net-core

As title suggests, I am creating open source project that is in .net core 2.0. here is the architecture of it.
Now, it's working fine with everything including code first, seeders, swagger UI, TDD etc.
But there are many places where I have to add/modify classes when I want to add new Table in Database (see SimpleCRUD.Model > Entities)
So, I think I can reduce that boilerplate code, but I am not sure what is best way to do it.
What I did so far?
I tried to create a windows app, which will check and generate code for new added entity.
What I am trying to achieve?
Is there anyway I can add some kind of code in my current project and that will check after each build? is it feasible? any other suggestion to make it working perfectly?
Reference
I have checked this working in few other frameworks like serenity, asp.net boilerplate etc.

T4 temples can help cut down the boiler plate...
https://dotnetthoughts.net/generate-your-database-entities-using-t4-templates/

You've asked for my help here
I agree with other posters that you might want to look into T4. It sounds like you also want to create an MSBuild task.
I outlined the steps to do this for a different question in post here
You can find my code generators under this folder, CodeGen.SessionProxies
The t4 example can be found here: AppSessionPartials.tt
The MSBuild task can be found here: GenerateSessionProxies.cs
I had it generating a nuget file through the CodeGen.SessionProxies.nuspec. You won't find it on nuget.com; I had a local nuget repository. It would be helpful to you to look at the corresponding install.ps1 to understand how to set the generator up as a msbuild task.
Disclaimer: All of the GitHub links are subject to break if I ever decide to clean up that repo.
Cheers

Related

How do I generate .d.ts typings from Flow code?

I have enabled Flow on a JavaScript project I am developing. Since I am putting in the effort to providing type annotations, I would really like to generate *.d.ts files so the broader TypeScript community can also have type information.
How can I generate *.d.ts type definition files from Flow-annotated JavaScript?
I searched for the available tools. I found the following.
The first one is the most up to date one. It can convert the whole Flow code to TypeScript. I have used it personally, and it works like a charm.
https://github.com/Khan/flow-to-ts
Other ones:
https://github.com/Kiikurage/babel-plugin-flow-to-typescript
https://github.com/burnnat/flow-to-dts
https://github.com/bcherny/flow-to-typescript
https://github.com/yuya-takeyama/flow2dts

why we are adding solution folder, and responsibilities share ,test folders inside solution

I have couple of the those pic I loaded.First my question about first pic.why those folders seems with dot presented.when I look ad those folsers,it says they are "solution folders".why we need this folder ,for example I am creating a class libabrary as a project.why should I decribe this project inside the "solution folders".
first pic.
second pic
my second question about this solution struture.which created by Layered Architecture Solution Guidance 2010 download from here http://visualstudiogallery.msdn.microsoft.com/c8c473b5-21a1-447a-8b24-33b43411ee7f
It's already had bll,dal,bo, folder,why we need a share folder.which classes should we put inside it and I also see a test folder.whats primary responsibilityies on this solution.and how it is used.
thank you all.
First Question: Those are solution folders, which are just a way of logically separating the different parts of the solution (layers, etc.). You can only have physical folders inside a project (the ones that aren't dotted-lined): Visual Studio Solutions Folder as real Folders
Second: A shared folder could be used for classes that don't neatly fit inside either the BLL or the DAL. I can't think of a reason off the top of my head for one, but I've seen examples where shared classes are created in RIA services for Silverlight.
Bonus: The tests folder is for holding your Unit Tests. Look up Unit Testing for ideas. It is very useful to write Unit Tests for your code to provide a first line of bug-fighting whenever you create (do my tests run successfully on my new code?) or modify (do my tests still run successfully on my existing code after this change I just made). NUnit is a popular open-source Unit Test framework, and MS provides its own Test Project Unit Test framework built into Visual Studio.

s#arp architecture + command and handler

This is my first time using S#arp Architecture 2.0 in a project.
There is two folders in tasks project : Commands and CommandHandlers.
I shearch about it and tried to undestand by the cookbook project what do i have to put there. I am imagining that i have to do something like it was before: a "viewToModel" function and a SaveOrUpdate in the IRepository.
Somebody can explain the "Commands and CommandHandlers" or/and give me a good documentation about it?
Thanks a lot!
Have you seen the Cookbook wiki? Using commands?
From your questions, I understand you are after some sort of CRUD functionality, in which case going for a command and handler approach might be overkill, just load the entity in your controller, copy values from the form and save it. Using commands is more suited for a Task based UI and where there is some behavior you want on the entities.

ASP.NET UI Generation

I'm Looking for some samples (will be better if they are open source) that enabling Programmer to Generate UI from Database.
I want to review them for the framework that i want to develop for myself.
Already i reviewed ASP.NET Dynamic Data and Nettiers.
Also i welcome your suggestions , tips , comments.
Have a look at a project I'm about to release, CodeGenerator. There is a sample project which illustrates how you can use CodeGenerator to quickly generate an entire administrative site. Have a look and let me know your thoughts.
BTW, this is just a small example of what CodeGenerator can do.
While perhaps not directly what you may want, have a look at Entity Framework Code First to let the code drive the DB model and it works well with existing databases.
Then with MVC you could use MVCScaffolding to generate your views but in this case it uses the Models not the DB directly.
It's a slightly different way than you might be looking for but it is still worth a look to help you as you look at this.

How to use FTS in SQLite with Monotouch for iOS

I'm looking to build an iOS app using Monotouch that has a rather large sqlite db full of text. I need to provide fast searching over this text.
My best solution right now is the FTS module (preferably version 4). I have read that the default instance of sqlite on iOS does not support FTS. If this is true what is the recommended way to build a custom instance of sqlite with Monotouch? Or can this be done at all?
I found this site describing how to accomplish this with xcode, but it is not clear how I would accomplish with Monotouch.
http://longweekendmobile.com/2010/06/16/sqlite-full-text-search-for-iphone-ipadyour-own-sqlite-for-iphone-and-ipad/
Any help is much appreciated!
As I mentioned in my comment above I got this working and since Stack Overflow has really helped me out I wanted to contribute a little to give back to the community.
Disclaimer
This is coming from a .NET developer who is a N00B when it comes to iOS/MacOS/XCode/Monotouch.
Although I tested this out on the iPad simulator I have yet to test it out on an actual device.
End disclaimer
This is a quick how-to compile your own version of SQLite and include it in your Monotouch project with the goal of supporting Full text search.
Step 1:
Download the SQLite amalgamation file.
This includes all of SQLite in one file.
http://www.sqlite.org/download.html
Step 2: Compile the SQLite source in Xcode for iOS.
There is a good walkthrough on how to do this here:
http://pp.hillrippers.ch/blog/2009/08/08/Static+SQLite+Library+with+Unicode+Support+for+the+iPhone/
I followed steps 1-5, skipped #6 since we're not adding additional headers.
Instead of using the compile flags used in the walk through I used:
SQLITE_ENABLE_COLUMN_METADATA
SQLITE_ENABLE_FTS4
There may be others you want to add as well.
These compile flags are added in XCode, to the "Build" tab of the project under "Preprocessor Macros".
Once you've compiled this you should have "mylibrary.a".
Step 3: Include this file in your MonoDevelop project
Add mylibrary.a into MonoDevelop as any other file, right click it and make sure the build action is 'Nothing'.
In your project options select "iPhone Build". You need to add additional mtouch arguments. Add the following
-gcc_flags "-L${ProjectDir} -lmylibrary -force_load ${ProjectDir}/mylibrary.a"
Step 4: Build a c# wrapper
You could probably find a good wrapper to include at this point but I just quickly rolled my own.
For a good tutorial on writing an SQLite wrapper in C# check this page out:
http://www.switchonthecode.com/tutorials/csharp-tutorial-writing-a-dotnet-wrapper-for-sqlite
Because your library is a part of the project you don't need to reference the library by name but instead use the "__Internal" keyword. *NOTE THERE ARE TWO UNDERSCORES IN "__INTERNAL" * (Don't ask me how much time I wasted before I realized that)
Here's a sample of one of mine
[DllImport ("__Internal", EntryPoint="sqlite3_open")]
static extern int sqlite3_open_v2(string filename, out IntPtr db);
There's obviously a lot more to putting together a wrapper, but there's lots of info out there on how to do that. One gotcha is to properly marshal the strings you get returned from SQLite. (see http://blog.gebhardtcomputing.com/2007/11/marshal-utf8-strings-in-net.html for more info on Marshaling)
This was intended to be a quick walkthrough on getting a native library compiled in into MonoDevelop/monotouch, and I hope it helps someone.
You would have to do the same thing, build your own libsqlite3.a, and mangle all the public exports so it doesn't conflict with the libsqlite loaded by the system, and then you would need to modify whatever library you want to bind to sqlite to [DllImport ("__Internal")] instead of libsqlite.

Resources