Services should be single instance classes that are used to access external resources such as web requests and files.
In StandardModule.cs
we are registering each service we use as a single instance:
builder.RegisterType<EnvironmentService>().As<IEnvironmentService>().SingleInstance();
builder.RegisterType<PreferencesService>().As<IPreferencesService>().SingleInstance();
[...]
These class types should all be placed inside the Services
directory of the project.
View Models are multi-instance classes which are tied to a View. These should be named the same as the view that they correspond to.
In StandardModule.cs
we are registering every class which matches the pattern *ViewModel
:
builder.RegisterAssemblyTypes(ThisAssembly)
.Where(t => t.Name.EndsWith("ViewModel"));
These class types should all be placed inside the ViewModels
directory of the project.
This makes code review easier when reading through the changes without an IDE open.
Yes:
Foo bar = new();
Example two = SomeClass.SomeMethodThatReturnsSomething();
No:
Foo bar = new Foo();
var baz = new Foo();
var two = SomeClass.SomeMethodThatReturnsSomething();
This one will fail the code quality check in Codacy if not followed.
Yes:
if (something)
{
return true;
}
No:
if (something)
return true;