Tuesday, December 12, 2017

Javascript : Create array sequence `[0, 1, ..., N-1]` in one line

http://www.jstips.co/en/javascript/create-range-0...n-easily-using-one-line/

Vues JS - POI - JSX

POI is a nice tool to create VueJS app without worrying about webpack configuration

Simply add this code in index.js file and run poi index.js

 

import Vue from "vue"

let data = { nom: 'Paul', age: 12 };

function mycomp (m) {
 return (
  Vue.component('m-c', {
   render() {
    return <div>Hello {m}</div>
   }
  })
 )
}

let template = (h, { nom, age }) =>
 <div style='color:red;'>
  <m-c></m-c>
  <div>Hello { nom } you are { parseInt(age) * 2 }</div>
 </div>

new Vue({
 el: "#app",
 render(h) {
  return template(h, data)
 },
 components: [mycomp('hal')]
})

Thursday, November 9, 2017

Read Connection String in .Net Core

In appsettings.json :

  "ConnectionStrings": {
    "Annuaire": "Server=SORA11\\MSSQL_APP;Database=Annuaire;User ID=****;Password=*****;Persist Security Info=False"
  }



https://stackoverflow.com/questions/39083372/how-to-read-connection-string-in-net-core

In Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    ...
    // Add the whole configuration object here.
    services.AddSingleton(Configuration);
}

In your controller add a field for the configuration and a parameter for it on a constructor

private readonly IConfiguration configuration;

public HomeController(IConfiguration config)
{
    configuration = config;
}

Now later in your view code you can access it like:

connectionString = configuration.GetConnectionString("DefaultConnection");