title: Create objects Type T in .Net Core
body: <p>I'm creating a web app in .net core and I'm trying to create a generic way to set and get "objects" from Session. The part of setting and getting I can do, my only problem is that I want to initialize the object if it doesn't exists on the session. The error that I get is that 'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'SessionExtensions.CreateObject()
  Can someone help me? 
  Thanks in the advance :)
  PS: here is my code:</p>
  
  <pre><code>public static class SessionExtensions
  {
      public static void Set&lt;T&gt;(this ISession session, string key, T value)
      {
          session.SetString(key, JsonConvert.SerializeObject(value));
      }
  
      public static T Get&lt;T&gt;(this ISession session, string key)
      {
          var value = session.GetString(key);
          return value == null ? CreateObject&lt;T&gt;() :
                                JsonConvert.DeserializeObject&lt;T&gt;(value);
      }
  
      public static T CreateObject&lt;T&gt;() where T : new()
      {
          return new T();
      }
  }
  </code></pre>