The preferred way of describing dependencies is by using constructor injection which follows Explicit Dependencies Principle:
ITestService.cs
public interface ITestService
{
int GenerateRandom();
}
TestService.cs
public class TestService : ITestService
{
public int GenerateRando...
Builtin container comes with a set of builtin features :
Lifetime control
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddTransient<ITestService, TestService>();
// or
services.AddScoped<ITestService, TestSer...
Once registered a dependency can be retrieved by adding parameters on the Controller constructor.
// ...
using System;
using Microsoft.Extensions.DependencyInjection;
namespace Core.Controllers
{
public class HomeController : Controller
{
public HomeController(ITestServic...
It's possible to create a new ASP.NET Core project entirely from the command line using the dotnet command.
dotnet new web
dotnet restore
dotnet run
dotnet new web scaffolds a new "empty" web project. The web parameter tells the dotnet tool to use the ASP.NET Core Empty template. Use...
Using Razor @functions keyword gives the capability of introducing classes and methods for inline use within a Razor file:
@functions
{
string GetCssClass(Status status)
{
switch (status)
{
case Status.Success:
return "alert-success&qu...
Returning partially applied functions is one technique to write concise code.
add :: Int -> Int -> Int
add x = (+x)
add 5 2
In this example (+x) is a partially applied function. Notice that the second parameter to the add function does not need to be specified in the function definitio...
Consider the character class [aeiou]. This character class can be used in a regular expression to match a set of similarly spelled words.
b[aeiou]t matches:
bat
bet
bit
bot
but
It does not match:
bout
btt
bt
Character classes on their own match one and only one character at a time...
Use to push commits made on your local branch to a remote repository.
The git push command takes two arguments:
A remote name, for example, origin
A branch name, for example,
master
For example:
git push <REMOTENAME> <BRANCHNAME>
As an example, you usually run git push orig...
Prelude is another popular starter kit. It features good support for various programming languages out-of-the-box including, notably - clojure. On *nix systems it can be installed with the following command:
curl -L https://git.io/epre | sh
Remote Validation used to check whether the content enter in the input control is valid or not by sending an ajax request to server side to check it.
Working
The RemoteAttribute works by making an AJAX call from the client to a controller action with the value of the field being validated. The con...
Once the Symfony Installer is available, create your first Symfony application with the new command:
# Linux, Mac OS X
$ symfony new my_project_name
# Windows
c:\> cd projects/
c:\projects\> php symfony new my_project_name
This command can be run from anywhere, not necessarily from t...
Given any value of type Int or Long to render a human readable string:
fun Long.humanReadable(): String {
if (this <= 0) return "0"
val units = arrayOf("B", "KB", "MB", "GB", "TB", "EB")
val digitGroups = (Mat...
In Kotlin you could write code like:
val x: Path = Paths.get("dirName").apply {
if (Files.notExists(this)) throw IllegalStateException("The important file does not exist")
}
But the use of apply is not that clear as to your intent. Sometimes it is clearer to create a ...
With this declaration:
fun Temporal.toIsoString(): String = DateTimeFormatter.ISO_INSTANT.format(this)
You can now simply:
val dateAsString = someInstant.toIsoString()
Let's say we want to replace only numbers with 2 digits: regular expression will find them with (\d\d)
SELECT REGEXP_REPLACE ('2, 5, and 10 are numbers in this example', '(\d\d)', '#')
FROM dual;
Results in:
'2, 5, and # are numbers in this example'
If I want to swap parts of the text, I us...
In the simple example, we simply set the width of the rectangle to that of it's parent. Let's consider a more complicated example:
ApplicationWindow {
visible: true
width: 400
height: 640
Rectangle{
id: rect
anchors.centerIn: parent
height: 100
...
Sample Data:
CREATE TABLE table_name ( id, list ) AS
SELECT 1, 'a,b,c,d' FROM DUAL UNION ALL -- Multiple items in the list
SELECT 2, 'e' FROM DUAL UNION ALL -- Single item in the list
SELECT 3, NULL FROM DUAL UNION ALL -- NULL list
SELECT 4, 'f,,g' FROM DUAL; -- NULL item...