Вредные советы .NET
разработчикам
Сергей Калинец
steer73
About Me
16 years in the business
In .NET since 2005
Love to code
Technical Architect @ Steer73
Никогда не мойте руки,
Шею, уши и лицо.
Это глупое занятье
Не приводит ни к чему.
Вновь испачкаются руки
Шея, уши и лицо.
Так зачем же тратить силы
Время попусту терять.
Стричься тоже бесполезно,
Никакого смысла нет.
К старости сама собою
Облысеет голова.
Вредные советы (Г. Остер)
We are different
• Windows
• GUI
• Visual Studio
• Remote Desktop
Console
• Is dark and old (it’s 2k17, c’mon!)
• Long commands for simple tasks
• Yet another language to know
TL;DR;
• .NET developer should use only what is included in Visual Studio, or
has VS extenstion, or has nuget.
• Every developer on the project should use Visual Studio
• And JS guys
• And they should add their files to *.csproj
First steps on new project
• Architecture
• Solution / project structure
• Layers
• Choosing of database / framework
Project structure
• Make many projects (e.g. at least 5 for datalayer)
• Create lot of folders and namespaces (services, services.core,
services.common, services.common.data)
• Always consider extracting a namespace into separate assembly
Layers (ASP.NET)
• Controller
• Service
• Repository
• DbContext
Data layer
• Only MS SQL (no NoSQL or Postgress)
• Only Entity Framework (no Dapper etc, we don’t want to use SQL in
2017)
• Use Repositories over DbContext (we need to abstract our persistence
layer)
• One Repository per entity
Regions
• Define sections for fields / methods / private / public
• Sections in large classes
• Sections in large methods
Inheritance
• Move commonly used methods into parent classes
• Make protected fields
• All ASP.NET controllers should have abstract parent!!!!
Code contracts
• Make your code even more enterprisy
• Combine with partial classes and TFS permissions
Magic: don’t
• Don’t use automapper
• Don’t use convention based code
Magic: ninject conventions
var? of course not
var addressList = new List<Address>(); // what???
List<Address> addressList = new List<Address>(); // OK
Always full names
var myAddress = addresses.Where(_ => _.Street == "...");
Always full names
var myAddress = addresses.Where(_ => _.Street == "...");
Address myAddress =
addresses.Where(address => address.Street == "...");
Working in Visual Studio
• Install packages via GUI, not package manage console
• Work with git via GUI as well – no console
• Try to avoid extensions
How to deploy?
Troubleshoot?
• Remote desktop (Remote Desktop Connection Manager)
• Zip and copy logs (share your disk and use tsclient)
• Remote debugging
Debugging
Comments
• Increase readability of the code
• Allows to hide unused (now) code
Ghostdoc: your friend
Ghostdoc: your friend
Спасибо

Вредные советы .NET разработчикам, Сергей Калинец

  • 1.
  • 2.
    About Me 16 yearsin the business In .NET since 2005 Love to code Technical Architect @ Steer73
  • 4.
    Никогда не мойтеруки, Шею, уши и лицо. Это глупое занятье Не приводит ни к чему. Вновь испачкаются руки Шея, уши и лицо. Так зачем же тратить силы Время попусту терять. Стричься тоже бесполезно, Никакого смысла нет. К старости сама собою Облысеет голова. Вредные советы (Г. Остер)
  • 6.
    We are different •Windows • GUI • Visual Studio • Remote Desktop
  • 7.
    Console • Is darkand old (it’s 2k17, c’mon!) • Long commands for simple tasks • Yet another language to know
  • 8.
    TL;DR; • .NET developershould use only what is included in Visual Studio, or has VS extenstion, or has nuget. • Every developer on the project should use Visual Studio • And JS guys • And they should add their files to *.csproj
  • 10.
    First steps onnew project • Architecture • Solution / project structure • Layers • Choosing of database / framework
  • 11.
    Project structure • Makemany projects (e.g. at least 5 for datalayer) • Create lot of folders and namespaces (services, services.core, services.common, services.common.data) • Always consider extracting a namespace into separate assembly
  • 12.
    Layers (ASP.NET) • Controller •Service • Repository • DbContext
  • 13.
    Data layer • OnlyMS SQL (no NoSQL or Postgress) • Only Entity Framework (no Dapper etc, we don’t want to use SQL in 2017) • Use Repositories over DbContext (we need to abstract our persistence layer) • One Repository per entity
  • 14.
    Regions • Define sectionsfor fields / methods / private / public • Sections in large classes • Sections in large methods
  • 15.
    Inheritance • Move commonlyused methods into parent classes • Make protected fields • All ASP.NET controllers should have abstract parent!!!!
  • 16.
    Code contracts • Makeyour code even more enterprisy • Combine with partial classes and TFS permissions
  • 17.
    Magic: don’t • Don’tuse automapper • Don’t use convention based code
  • 19.
  • 21.
    var? of coursenot var addressList = new List<Address>(); // what??? List<Address> addressList = new List<Address>(); // OK
  • 22.
    Always full names varmyAddress = addresses.Where(_ => _.Street == "...");
  • 23.
    Always full names varmyAddress = addresses.Where(_ => _.Street == "..."); Address myAddress = addresses.Where(address => address.Street == "...");
  • 24.
    Working in VisualStudio • Install packages via GUI, not package manage console • Work with git via GUI as well – no console • Try to avoid extensions
  • 26.
  • 27.
    Troubleshoot? • Remote desktop(Remote Desktop Connection Manager) • Zip and copy logs (share your disk and use tsclient) • Remote debugging
  • 28.
  • 29.
    Comments • Increase readabilityof the code • Allows to hide unused (now) code
  • 30.
  • 31.
  • 32.