
Github Url: https://github.com/huseyindeniz/EnterpriseAppTemplateForDotNetCore
Test App Url: http://dotnetcore.huseyindeniz.net
Test App Notes:
- running on Centos 7
- code first with fluent api (with postgresql provider)
Development Notes
dot net core install on centos 7
- yum install libunwind libicu
- curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=835019 ( dotnet core 1.0)
- mkdir -p /home/opt/dotnet
- tar zxf dotnet.tar.gz -C /home/opt/dotnet
- ln -s /home3/opt/dotnet/dotnet /usr/local/bin
- curl -sSL -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=836297
(extract only 1.1.0 dir to /home/opt/dotnet/shared/Microsoft.NETCore.App, so you would get 1.0.3 and 1.1.0 at the same time) - to test if it is working
- mkdir hwapp
- cd hwapp
- dotnet new
- dotnet restore
- dotnet run ( after this if you see hello world, it is working)
apache proxy conf
add this to apache conf
<VirtualHost yourappdomain:80>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ErrorLog /var/log/httpd/yourappname-error.log
CustomLog /var/log/httpd/yourappname-access.log common
</VirtualHost>
if you are using cpanel you need something like this
- create dir /etc/apache2/conf.d/userdata/std/2_4/cpanelusername/yourdomainname
- add proxy.conf file to this dir and add following lines to that file
- ProxyPreserveHost On
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/
ErrorLog /home3/log/dotnetcore-yourdomainname-error.log
CustomLog /home3/log/dotnetcore-yourdomainname-access.log common
- ProxyPreserveHost On
- /scripts/ensure_vhost_includes –all-users
- systemctl restart httpd
publish your app
- in your mvc app right click an publish
- copy publish dir to /home/patthoyourpublishdir/ in server
Create service for your app
- create file as /etc/systemd/system/kestrel-yourdomainname.service and fill it with the following
- [Unit]
Description=Example .NET Web API Application running on CentOS 7[Service]
ExecStart=/usr/local/bin/dotnet /home/patthoyourpublishdir/yourappname.dll
WorkingDirectory=/home/patthoyourpublishdir/
Restart=always
RestartSec=10 # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=dotnet-example
User=root or cpanel username
Group=root or cpanel username
Environment=ASPNETCORE_ENVIRONMENT=Production[Install]
WantedBy=multi-user.target
- [Unit]
- systemctl enable kestrel-hdnet.service (if something goes wrong disable it)
- systemctl start kestrel-hdnet.service
- systemctl status kestrel-hdnet.service
and your dotnetcore mvc application should work.
I will add detailed documentation later.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
using hdnet.Domain.Blog.Entity; using hdnet.Domain.Blog.Service.Read; using hdnet.Domain.Shared.Helper.DataGrid; using hdnet.Domain.Shared.Repository; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace hdnet.Application.Service.Blog.Read { public class ServiceReadPost : IServiceReadPost { private readonly IRepository<Post, long> _postRepository; public ServiceReadPost( IRepository<Post, long> postRepository ) { this._postRepository = postRepository; } public Post GetById(long id) { return this._postRepository.Table.Where(p => p.Id == id).SingleOrDefault(); } public IQueryable GetByIdQuery(long id) { IQueryable query = this._postRepository.Table; query = query.Where(gd => gd.Id == id); return query; } public IQueryable GetByNameQuery(string name) { IQueryable query = this._postRepository.Table; query = query.Where(gd => gd.Name == name); return query; } public IQueryable GetListQuery( IHelperDataGridFilter filter = null , IHelperDataGridSorter sorter = null , IHelperDataGridPaginator paginator = null) { IQueryable query = this._postRepository .Table ; if (filter != null) { query = filter.ApplyFilters(query); } if (sorter != null) { query = sorter.ApplySorters(query); } if (paginator != null) { query = paginator.ApplyPaginator(query); } return query; } } } |