Giter Site home page Giter Site logo

markrendle / simple.web Goto Github PK

View Code? Open in Web Editor NEW
231.0 31.0 67.0 12.06 MB

A lightweight, object-oriented (Model-View-Handler) framework for modern web development in .NET.

License: MIT License

Ruby 2.16% Shell 0.07% Puppet 0.13% PowerShell 0.52% C# 97.13%

simple.web's Introduction

Simple.Web

Simple.Web is a REST-focused, object-oriented Web Framework for .NET 4. More information on it's background can be found here.

BUILD

You can build Simple.Web using the command-line options outlined below, or simply through MS Visual Studio or MonoDevelop. It is recommended that anyone planning to contribute to the project familiarise themselves with the command-line as it will be the successful completion of this build process that will stand your pull-request in good stead.

Command-Line

Ruby

The command-line process uses RAKE, a Ruby build system. It will therefore be necessary to have Ruby >= 1.9.2 installed. Dependent on your operating system there are several options to accomplish this but we first recommend you can check current installation by typing ruby -v from console prompt.

For example:

> ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]

If you do not yet have Ruby installed on your system check out RubyInstaller (for Windows) or RVM (for *nix). You can also use RVM to install and manage multiple versions of Ruby in a *nix environment.

Rake

RubyGems are Ruby's own managed packages and it's through this system we need to install some build dependencies. To simplify their installation simply type the following at the console prompt:

Windows:

> .\InstallGems.bat  

*nix:

> ./installgem.sh

Using Ruby's gem utility it should install the Bundler, RAKE, and Albacore gems. You can check currently installed gems at any time by typing gem list --local from a console prompt.

Building

From the root of the repository you can see all available build tasks by typing:

> rake -T

rake build     # Build
rake clean     # Remove any temporary products.
rake clobber   # Remove any generated file.
rake full      # Build + Tests + Specs
rake publish   # Build + Tests + Specs + Publish (remote)
rake publocal  # Build + Tests + Specs + Publish (local)
rake quick     # Build + Unit tests
rake test      # Build + Tests (default)

You can specify any of these tasks when building Simple.Web, or simply just type rake for it's configured default.

Task: Build + ...

The variation available is to faciliate faster repetitive build times depending on your current workflow. For example if you are regularly compiling mid-development you may choose rake quick which confines it's boundary to unit tests. If you are looking for greater assurance rake test (the default) will run both unit and integration tests. Finally you can choose rake full to run all tests and specifications.

Task: Clean

This will remove all intermediate files creating during the build process, but leave build artifacts and results intact.

Task: Clobber

This will remove all build-time generated files, effectively restoring your repository to that in source control. This should be the same as performing git clean -xfd.

Task: Publish / Publocal

Allows you to package Simple.Web's nuget packages and publish to either NuGet.org using rake publish, or an alternative nuget server using rake publocal.

To enable publishing you will need to set the appropriate environment variables:

rake publish
  apiurl_local -- NuGet server url (e.g. "http://nuget.org")
  apikey_local -- ServerAPI key that authenticates your publish

rake publocal
  apiurl_remote -- NuGet server url (e.g. "http://nuget.local")
  apikey_remote -- Server API key that authenticates your publish

NOTES

Mono 2.10.x

Due to a [variance validity bug] 1 in Mono 2.10.x you will require version 3.x (MDK Installer recommended). We continue to petition Xamarin to make another 2.x STABLE release to address this. In the meantime our continuous integration setup will continue to run against 2.x STABLE and 3.x BETA releases of Mono.

NuGet.exe on *nix with Mono

If you are running on *nix or OS X Darwin (before Mountain Lion) you may need to tell Mono which certificate authorities to trust when performing NuGet operations over https:

> sudo mozroots --import --sync 

Mozilla Roots Importer - version 3.0.2.0
Download and import trusted root certificates from Mozilla's MXR.
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

Downloading from 'http://mxr.mozilla.org/seamonkey/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1'...
Importing certificates into user store...
140 new root certificates were added to your trust store.
Import process completed.

CONTRIBUTE

Contributions to Simple.Web are gratefully received but we do ask you to follow certain conditions:

  • Fork the main markrendle/Simple.Web
  • Use a branch when developing in your own forked repository, DO NOT work against master
  • Write a unit test to validate new logic, ideally using TDD
  • Ensure all projects build and tests pass, use the command-line option rake full
  • Make a pull request from your-fork/your-branch to Simple.Web/master
  • Provide a description of the motivation behind the changes

.. but all that said, don't be afraid :-)

VERSION

Versioning is of assemblies and nuget packages is dictated by that specified through VERSION.txt. The main contributors to the project will manage releases and SemVer-compliant version numbers. We ask you do not include VERSION.txt in any of your pull-requests, just indicate in it's accompanying description any thoughts in this direction.

SUPPORT

Any problems raise an issue or shout and will get straight on it.

simple.web's People

Contributors

andycross avatar eddiegarmon avatar hoetz avatar i-e-b avatar ianbattersby avatar jjvdangelo avatar markrendle avatar mastoj avatar mickdelaney avatar rkevinstout avatar sagacity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple.web's Issues

CodeGeneration.Tests FAIL

Simple.Web.CodeGeneration.Tests.HandlerRunnerBuilderTest.CallsPatchWithParameter [FAIL]
   Simple.Web.UnsupportedMediaTypeException : Requested type(s) not available
   Stack Trace:
      c:\Source\GitHub\Simple.Web\Simple.Web\Behaviors\Implementations\SetInput.cs(45,0): at Simple.Web.Behaviors.Implementations.GetInput.Impl[T](IContext context)
      at lambda_method(Closure , Object , IContext )
      c:\Source\GitHub\Simple.Web\Tests\Simple.Web.CodeGeneration.Tests\HandlerRunnerBuilderTest.cs(75,0): at Simple.Web.CodeGeneration.Tests.HandlerRunnerBuilderTest.CallsPatchWithParameter()

iis 404

Hi all,

I'm trying to use Owin with iis and I keep getting 404 because the MVC handlers are being called instead for the Owin ones.

I have added Owin to the web.config handlers and it works for IIS express but not for IIS

Part of my web.config file:

<system.webServer>



</system.webServer>

Startup class

public partial class Startup
{
public void Configuration(IAppBuilder builder)
{
builder.Map("/resources", sw => sw.UseSimpleWeb());
}
}

The handler I'm trying to test.

[UriTemplate("/resources/home")]
public class GetIndex : IGet, IOutput
{
readonly DataService _dataService;

    public GetIndex(DataService dataService)
    {
        _dataService = dataService;
    }
    public Status Get()
    {
        this.Output = "OwinHost runnnig Simple.Web!";

        return 200;
    }

    public RawHtml Output { get; set; }
}

Thanks in advance for your help.

rake fails to build one project

I've been having some problems with using rake which I can't figure out. Everything works just fine when building in Visual Studio but when building with rake I get the following error:

"C:\dev\git\Simple.Web\src\Simple.Web.sln" (Clean;Build target) (1) ->
"C:\dev\git\Simple.Web\src\Tests\DefaultSimpleContainer.Test\DefaultSimpleContainer.Test.csproj" (default target) (3:2) ->
(CheckPrerequisites target) ->
C:\dev\git\Simple.Web\src\.nuget\NuGet.targets(77,5): error MSB4175: The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Build.Tasks.v4.0.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Build.Tas ks.v4.0.dll' or one of its dependencies. The system cannot find the file specified
[C:\dev\git\Simple.Web\src\Tests\DefaultSimpleContainer.Test\DefaultSimpleC ontainer.Test.csproj]

It seems like when the project DefaultSimpleContainer.Tests is built the MSBuildToolsPath points to the MSBuild bin folder, but for the other projects it is pointing to ...Microsoft.NET\Framework\v4.0.30319 where the missing dll is located. I noticed that the project is targeting 4.5, but changing to 4 didn't help for me. I've been looking for a MSBuild that is pointing to the Framework folder instead of MSBuild\bin but haven't found one.

I'm running on Windows 8 with VS12 and VS13 preview installed if that is relevant.

Workaround:
Copy the Microsoft.Build.Tasks.v4.0.dll from C:\Windows\Microsoft.NET\Framework\v4.0.30319 to C:\Program Files (x86)\MSBuild\12.0\Bin.

Generic arguments in UriTemplates

Allow generic type arguments to be included as part of the UriTemplate, so you can do things like this:

[UriTemplate("/{TModel}/{Id}")]
[ValidTypes(typeof(Album), typeof(Artist), typeof(Label))]
public class GetModel : IGet, IOutput<TModel>
{
    public Status Get()
    {
        var db = Database.Open();
        Output = db[typeof(TModel).Name].Get(Id);
        return Output != null ? 200 : 404;
    }

    public int Id { get; set; }
    public TModel Output { get; private set; }
}

StringBuilderStream for serialization tests?

Mark, what do you think about switching to a stream class that auto memo-izes the data written to it to a string, and makes that data available via a 'WrittenContent' string value?

No type was found called OwinAppSetup with a method taking a valid parameter type

This might be a bug that should be filed in the Fix project, but I found it using Simple.Web. I'm trying to do the simplest thing possible, just create a "Hello world" project based on the empty web app template in Visual Studio. Step to recreate:

  1. New empty web project
  2. install-package Simple.Web
  3. install-package Simple.Web.AspNet
  4. F5, run --> Boom!

I have the default OwinAppSetup class, added by Fix.AspNet I think(?). So there's something weird going on here.

Simple.Web.JsonFx.Tests [FAIL] (Mono only)

xUnit.net console test runner (32-bit .NET 4.0.30319.17020)
Copyright (C) 2007-11 Microsoft Corporation.

xunit.dll:     Version 1.9.0.1566
Test assembly: /Users/ian/code/Simple.Web/test/Simple.Web.JsonFx.Tests.dll

Simple.Web.JsonFx.Tests.JsonFxContentTypeHandlerTests.PicksUpOrdersLinkFromCustomers [FAIL]
   JsonFx.Serialization.SerializationException : Invalid IL code in (wrapper dynamic-method) object: (object): IL_0001: call      0x00000001


   ---- System.InvalidProgramException : Invalid IL code in (wrapper dynamic-method) object: (object): IL_0001: call      0x00000001
   Stack Trace:
     at JsonFx.Serialization.DataWriter`1[JsonFx.Model.ModelTokenType].Write (System.Object data, System.IO.TextWriter output) [0x00000] in <filename unknown>:0 
     at Simple.Web.JsonFx.JsonMediaTypeHandler.Write (IContent content, System.IO.Stream outputStream) [0x00000] in <filename unknown>:0 
     at Simple.Web.JsonFx.Tests.JsonFxContentTypeHandlerTests.PicksUpOrdersLinkFromCustomers () [0x00000] in <filename unknown>:0 
     at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
     at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
   ----- Inner Stack Trace -----
     at (wrapper managed-to-native) System.Delegate:CreateDelegate_internal (System.Type,object,System.Reflection.MethodInfo,bool)
     at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x00000] in <filename unknown>:0 
     at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0 
     at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0 
     at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in <filename unknown>:0 
     at JsonFx.CodeGen.DynamicMethodGenerator.GetPropertyGetter (System.Reflection.PropertyInfo propertyInfo) [0x00000] in <filename unknown>:0 
     at JsonFx.Serialization.Resolvers.MemberMap..ctor (System.Reflection.PropertyInfo propertyInfo, DataName dataName, JsonFx.Serialization.Resolvers.ValueIgnoredDelegate isIgnored) [0x00000] in <filename unknown>:0 
     at JsonFx.Serialization.Resolvers.ResolverCache.BuildMap (System.Type objectType, IDictionary`2& maps) [0x00000] in <filename unknown>:0 
     at JsonFx.Serialization.Resolvers.ResolverCache.LoadTypeName (System.Type type) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTypeName (System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetArrayTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, IEnumerable value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetObjectTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, DataName typeName, IEnumerator`1 enumerator) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetArrayTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, IEnumerable value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetArrayTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, IEnumerable value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTokens (System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Serialization.DataWriter`1[JsonFx.Model.ModelTokenType].Write (System.Object data, System.IO.TextWriter output) [0x00000] in <filename unknown>:0

Tests complete: 1 of 2
Simple.Web.JsonFx.Tests.JsonFxContentTypeHandlerTests.PicksUpOrdersLinkFromCustomer [FAIL]
   JsonFx.Serialization.SerializationException : Invalid IL code in (wrapper dynamic-method) object: (object): IL_0001: call      0x00000001


   ---- System.InvalidProgramException : Invalid IL code in (wrapper dynamic-method) object: (object): IL_0001: call      0x00000001
   Stack Trace:
     at JsonFx.Serialization.DataWriter`1[JsonFx.Model.ModelTokenType].Write (System.Object data, System.IO.TextWriter output) [0x00000] in <filename unknown>:0 
     at Simple.Web.JsonFx.JsonMediaTypeHandler.Write (IContent content, System.IO.Stream outputStream) [0x00000] in <filename unknown>:0 
     at Simple.Web.JsonFx.Tests.JsonFxContentTypeHandlerTests.PicksUpOrdersLinkFromCustomer () [0x00000] in <filename unknown>:0 
     at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
     at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
   ----- Inner Stack Trace -----
     at (wrapper managed-to-native) System.Delegate:CreateDelegate_internal (System.Type,object,System.Reflection.MethodInfo,bool)
     at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClosed) [0x00000] in <filename unknown>:0 
     at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0 
     at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0 
     at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) [0x00000] in <filename unknown>:0 
     at JsonFx.CodeGen.DynamicMethodGenerator.GetPropertyGetter (System.Reflection.PropertyInfo propertyInfo) [0x00000] in <filename unknown>:0 
     at JsonFx.Serialization.Resolvers.MemberMap..ctor (System.Reflection.PropertyInfo propertyInfo, DataName dataName, JsonFx.Serialization.Resolvers.ValueIgnoredDelegate isIgnored) [0x00000] in <filename unknown>:0 
     at JsonFx.Serialization.Resolvers.ResolverCache.BuildMap (System.Type objectType, IDictionary`2& maps) [0x00000] in <filename unknown>:0 
     at JsonFx.Serialization.Resolvers.ResolverCache.LoadTypeName (System.Type type) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTypeName (System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetArrayTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, IEnumerable value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetObjectTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, DataName typeName, IEnumerator`1 enumerator) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetArrayTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, IEnumerable value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTokens (System.Collections.Generic.List`1 tokens, ICycleDetector detector, System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Model.ModelWalker.GetTokens (System.Object value) [0x00000] in <filename unknown>:0 
     at JsonFx.Serialization.DataWriter`1[JsonFx.Model.ModelTokenType].Write (System.Object data, System.IO.TextWriter output) [0x00000] in <filename unknown>:0

Tests complete: 2 of 2
2 total, 2 failed, 0 skipped, took 0.456 seconds

ordering of link writing

should links be written in an alpha-numeric order on the href element for consistency and the ability to ensure in testing that all links are correct not just the count of them?

ContinueWithHandler in AsyncPipeline misses unwrap

Not sure about this but I think that

private static Task ContinueWithHandler(Task task, Func<THandler, IContext, Status> continuation, IContext context, THandler handler)

misses the Unwrap of the task

Discuss: change to Input?

I'm wondering if the IInput interface with an Input property might be a bit crufty, and whether having IPost, IPut and so on might be better?

URI Templates No Longer Working (0.7)

After updating my NuGet packages (Simple.Web, Simple.Web.AspNet, Simple.Web.Razor, Simple.Web.StructureMap) to 0.7 from 0.6, my URI templates no longer work. I am getting a 403 for every handler.

I am using a .NET 4.5 project, on Windows 8 with IIS 8.

CORS headers not making it into the response

Not sure if this should be opened up on Fix or Simple.Web, but here goes.

It appears that the CORS headers are not being written to cross-origin requests. I have configured a simple site to that uses "*" and none of the cross-origin requests coming back have the header and, as expected, the browser chokes.

IPathResolver

Shouldn't there be host specific implementations of this interface? Also, wouldn't this be a host service, and should therefore be injected into the environment before Simple.Web handles the request? If so, the locator code should probably look in the environment before reflecting.

Discuss: change to Redirect?

At the moment, there's the IMayRedirect interface, which adds a Location property.

As an alternative, how about an extra Location property on Status which can only be set via static methods for each of the Redirect status values.

So instead of

public class ... : IPost, IMayRedirect
{
    public Status Post()
    {
        ...
        Location = "/whatever";
        return Status.SeeOther;
    }

    public string Location { get; private set; }
}

You'd have

public class ... : IPost
{
    public Status Post()
    {
        ...
        return Status.SeeOther("/whatever");
    }
}

Unless anyone has any objections, this is going to happen.

If Views are in a different project than the hosting class the views won't be found

I have a sample project showing the problem: https://github.com/mastoj/NestDemo/tree/DecoupleHosting

I am doing self hosting in two different ways. First I had it in the NestDemo project, but than I wanted to decouple hosting from application and tried to put the hosting in a separate project, NestDemo.SelfHost. That didn't work since AssemblyAppRoot in RazorViews removes the bin/debug part of the file path which is needed I think if you have the hosting and application separated.

Problem deploying to azure

I built a very simple website just to try out simple web and razor. It works as expected locally but fails when I deploy to azure with the following config error:

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error:

Line 15:
Line 16:
Line 17:
Line 18:
Line 19:

It tells me the issue is on line 17 which reffers to the System.Web.Mvc assembly. I've ensured it's properies are set to local but that didn't help. Any ideas?

Thanks in advance!

Add file watch to the razor files

When a razor file is compiled it would be nice if a file watch got added to it so changes in the razors could be caught immediately when doing development without the need for a full recompile of the project.

Ninject Mono - Object Reference Not Set

Seems the ActivationBlock in NinjectContainer (although not null) gives a Object Reference Not Set.

HandlerBuilderFactory

I'm still not 100% sure if this is an issue in NinjectContainerScope or Ninject itself but am happy the 'hidden complexity' is HandlerFactoryBuilder is OK (nb: v3 is supposed to be Mono 2/4 compatible) :-

handlerBlock = ".Block(Simple.Web.Ninject.Tests.TestHandler $var1) {\r\n    $var1 = .Call $var2.Get();\r\n    .If (\r\n        .Call $var3.ContainsKey(\"IsDisposed\")\r\n    ) {\r\n        .Try {\r\n            $var1.IsDisposed = (System.Boolean).Call Simple.Web.CodeGeneration.PropertySetterBuilder.SafeConvert(\r\n                ($var3.Item[\"IsDisposed\"])[0],\r\n                .Constant<System.RuntimeType>(System.Boolean))\r\n        } .Catch (System.Exception) {\r\n            $var1.IsDisposed = .Default(System.Boolean)\r\n        }\r\n    } .Else {\r\n        .Default(System.Void)\r\n    };\r\n    .If (\r\n        .Call $var3.ContainsKey(\"TestProperty\")\r\n    ) {\r\n        .Try {\r\n            $var1.TestProperty = (System.String).Call Simple.Web.CodeGeneration.PropertySetterBuilder.SafeConvert(\r\n                ($var3.Item[\"TestProperty\"])[0],\r\n                .Constant<System.RuntimeType>(System.String))\r\n        } .Catch (System.Exception) {\r\n            $var1.TestProperty = .Default(System.String)\r\n        }\r\n    } .Else {\r\n        .Default(System.Void)\r\n    };\r\n    $var1\r\n}"

scopeBlock =     
    [0]: {(Param_0 = value(Simple.Web.Ninject.NinjectContainer).BeginScope())}
    [1]: {(Param_0 = {var Param_1; ... })}
    [2]: {Param_0}
    [3]: {(Param_0 = Create(Param_1, Param_2))}
    [4]: {Param_0}

Unit test error

xunit.dll: Version 1.9.0.1566
Test assembly: ./test/Simple.Web.Ninject.Tests.dll

Simple.Web.Ninject.Tests.HandlerFactoryBuilderTests.CreatesInstanceOfType [FAIL]
System.NullReferenceException : Object reference not set to an instance of an object
Stack Trace:
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.getParentDefinitionMethodInfo () [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.MethodInfo method, BindingFlags flags) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.PropertyInfo property) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined (System.Reflection.PropertyInfo element, System.Type attributeType, Boolean inherit) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.HasAttribute (System.Reflection.MemberInfo member, System.Type type) [0x00000] in :0 
at Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject (System.Reflection.MemberInfo member) [0x00000] in :0 
at Ninject.Selection.Selector+<>cDisplayClass3.b2 (IInjectionHeuristic h) [0x00000] in :0 
at System.Linq.Enumerable.AnyIInjectionHeuristic [0x00000] in :0 
at Ninject.Selection.Selector.b1 (System.Reflection.PropertyInfo p) [0x00000] in :0 
at System.Linq.Enumerable+cIterator351[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0 
at System.Collections.Generic.List1[System.Reflection.PropertyInfo].AddEnumerable (IEnumerable1 enumerable) [0x00000] in <filename unknown>:0 
at System.Collections.Generic.List1[System.Reflection.PropertyInfo].AddRange (IEnumerable1 collection) [0x00000] in <filename unknown>:0 
at Ninject.Selection.Selector.SelectPropertiesForInjection (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute (IPlan plan) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner+<>c__DisplayClass1.<CreateNewPlan>b__0 (IPlanningStrategy s) [0x00000] in <filename unknown>:0 
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[IPlanningStrategy] (IEnumerable1 series, System.Action1 action) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner.CreateNewPlan (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner.GetPlan (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Activation.Providers.StandardProvider.Create (IContext context) [0x00000] in <filename unknown>:0 
at Ninject.Activation.Context.Resolve () [0x00000] in <filename unknown>:0 
at Ninject.KernelBase+<>c__DisplayClass10.<Resolve>b__c (IBinding binding) [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator272[Ninject.Planning.Bindings.IBinding,System.Object].MoveNext () [0x00000] in :0 
at System.Linq.Enumerable+c_Iterator171[Simple.Web.Ninject.Tests.TestHandler].MoveNext () [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable.Single[TestHandler] (IEnumerable1 source, System.Func2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable.SingleOrDefault[TestHandler] (IEnumerable1 source) [0x00000] in :0 
at Ninject.ResolutionExtensions.TryGetTestHandler [0x00000] in :0 
at Ninject.ResolutionExtensions.TryGetTestHandler [0x00000] in :0 
at Simple.Web.Ninject.NinjectContainerScope.GetTestHandler [0x00000] in :0 
at (wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure,System.Collections.Generic.IDictionary`2)
at Simple.Web.Ninject.Tests.HandlerFactoryBuilderTests.CreatesInstanceOfType () [0x00000] in :0 
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0

Simple.Web.Ninject.Tests.HandlerFactoryBuilderTests.DisposesInstances [FAIL]
System.NullReferenceException : Object reference not set to an instance of an object
Stack Trace:
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.getParentDefinitionMethodInfo () [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.MethodInfo method, BindingFlags flags) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.PropertyInfo property) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined (System.Reflection.PropertyInfo element, System.Type attributeType, Boolean inherit) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.HasAttribute (System.Reflection.MemberInfo member, System.Type type) [0x00000] in :0 
at Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject (System.Reflection.MemberInfo member) [0x00000] in :0 
at Ninject.Selection.Selector+<>cDisplayClass3.b2 (IInjectionHeuristic h) [0x00000] in :0 
at System.Linq.Enumerable.AnyIInjectionHeuristic [0x00000] in :0 
at Ninject.Selection.Selector.b1 (System.Reflection.PropertyInfo p) [0x00000] in :0 
at System.Linq.Enumerable+cIterator351[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0 
at System.Collections.Generic.List1[System.Reflection.PropertyInfo].AddEnumerable (IEnumerable1 enumerable) [0x00000] in <filename unknown>:0 
at System.Collections.Generic.List1[System.Reflection.PropertyInfo].AddRange (IEnumerable1 collection) [0x00000] in <filename unknown>:0 
at Ninject.Selection.Selector.SelectPropertiesForInjection (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute (IPlan plan) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner+<>c__DisplayClass1.<CreateNewPlan>b__0 (IPlanningStrategy s) [0x00000] in <filename unknown>:0 
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[IPlanningStrategy] (IEnumerable1 series, System.Action1 action) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner.CreateNewPlan (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner.GetPlan (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Activation.Providers.StandardProvider.Create (IContext context) [0x00000] in <filename unknown>:0 
at Ninject.Activation.Context.Resolve () [0x00000] in <filename unknown>:0 
at Ninject.KernelBase+<>c__DisplayClass10.<Resolve>b__c (IBinding binding) [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator272[Ninject.Planning.Bindings.IBinding,System.Object].MoveNext () [0x00000] in :0 
at System.Linq.Enumerable+c_Iterator171[Simple.Web.Ninject.Tests.TestHandler].MoveNext () [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable.Single[TestHandler] (IEnumerable1 source, System.Func2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable.SingleOrDefault[TestHandler] (IEnumerable1 source) [0x00000] in :0 
at Ninject.ResolutionExtensions.TryGetTestHandler [0x00000] in :0 
at Ninject.ResolutionExtensions.TryGetTestHandler [0x00000] in :0 
at Simple.Web.Ninject.NinjectContainerScope.GetTestHandler [0x00000] in :0 
at (wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure,System.Collections.Generic.IDictionary`2)
at Simple.Web.Ninject.Tests.HandlerFactoryBuilderTests.DisposesInstances () [0x00000] in :0 
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0

2 total, 2 failed, 0 skipped, took 0.609 seconds

IoC release

ISimpleContainer current only has a Get method, but it might be very useful to have a way of releasing components as well.

For instance, when using objects that are not thread-safe I would want to be able to create them when a handler starts and release them at the end of the handler, so they don't get reused by another request in the threadpool.

One of the ways this can be done is by exposing a nested container approach. In NInject this is called an activation block I believe, and in StructureMap this is called, well, a nested container (I'm sure you can guess which container I'm currently using :)).

Using ICacheability does not seem to affect response headers

When using the current NuGet pacakge and implementing ICacheability on a handler, the response headers don't appear to reflect the CacheOptions.

public CacheOptions CacheOptions {
    get {
        return new CacheOptions(new TimeSpan(0, 0, 0))
        {
            Level = CacheLevel.None
        };
    }
}

    // Or...

public CacheOptions CacheOptions {
    get { return CacheOptions.DisableCaching; }
}

Creating a simple GET request in Fiddler shows that the request:

GET: http://localhost:53305/

Host: localhost:53305
Connection: keep-alive
Accept: application/json, text/plain, /
X-Requested-With: XMLHttpRequest
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

Receives this response (using IISExpress/VS2012):

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 01 Oct 2013 20:23:19 GMT
Content-Length: 9

While I am using NoCache (and IISExpress) as the description for the bug, the same headers are returned when using something such as (or using it in IIS7.5/8):

public CacheOptions CacheOptions {
    get {
        return new CacheOptions(new TimeSpan(1, 0, 0))
        {
            Level = CacheLevel.Public
        };
    }
}

DLLs in output folder are not loaded when compiling razor view

This might be something by design, but I think this should be fixed. I started playing with simple.web last week and one of the things I wanted to setup was js and css optimization like the one for regular MVC. To do that in a useful way I need to use a helper from another assembly in the view, and it turns out I can't do that since the assemblies that are loaded are only the ones specified by the types of the model or the handler when compiling the razor view.

My suggestion is to load all the assemblies that is in the output folder when compiling the razor view so it is possible to use helper methods from other assemblies than just the ones specified by the model, handler or the project assembly.

Open For Extension ... Your thoughts.

Hi,

I like Simple.Web's simplicity. However, I'm looking to extend the functionality.

After taking a look at Simple.Web.Application it seems kinda hard.

I'd like access to the routing table to determine if a route exists.

If the route does not exist, I'd like to have a "catch all" route that will process the request.

In an ideal world & work flow, I'd love to have the following directory layout for my website:

.
|-- Web.config
|-- _layout.cshtml
|-- index.cshtml
|-- about.cshtml
|-- contact.cshtml
|-- api
|   `-- search.cs
|-- account
|   |-- AuthenticatedAccount.cs
|   |-- _layout.cshtml
|   |-- dashboard
|   |   |-- index.cs
|   |   `-- index.cshtml
|   |-- contacts
|   |   |-- add.cs
|   |   |-- add.cshtml
|   |   `-- index.cshtml
|   `-- reports
|-- search
    `-- index.cshtml

1. Custom Routing

As a startup task, I'd like to "override" the route finding mechanism in Simple.Web. In my mapping strategy I wouldn't rely on [UriTemplate] to build my routes... I would want to map IPost and IGet (and others) automatically based on the actual directory structure.

2. No Drama Razor Pages & Layouts

I'd like to simply "drop in" a cshtml file in any location -- and have it automatically served. Currently, I have to go through a Handler in order to get a page served. Even if it's a simple IGet request that displays some general information.

Sure, I can use static HTML files, but then I lose the ability to leverage site-wide layouts and creating simple dynamic pages.

3. Using Simple.Web when I want it

The /account/contacts has the following files:

|   |-- contacts
|   |   |-- add.cs
|   |   |-- add.cshtml
|   |   `-- index.cshtml

public class add : AuthenticatedAccount, IPost<Contact>{
    public Status Post(Contact c){
         // add the contact.
    }
}
  • A GET /contacts would render index.cshtml.
  • A GET /contacts/add would render add.cshtml since there's no IGet on the add handler.
  • A POST /contacts/add would execute add.cs as normal, then the handler would be given to add.cshtml for rendering.
  • A POST /contacts would not execute any handlers, but it would render /contacts/index.html and post data would be available to the page if it wanted it.

Maybe what I'm looking for isn't in the perview of Simple.Web, but at a very minimum, it would be cool to have the ability to access/modify the routing table, access the razor engine, and have the ability to do before and after processing a handler is executed, and/or some kind of {catchall} mechanism.

Your thoughts?
Brian

404 vs 204

Hi Mark,

Sorry if log this as issue because it isn't, but 140 chars on twitter won't be enough for me to ask my question.

I'm not an expert in rest but I have always been under the impression that if the system doesn't find a resource given an id (resource doesnt exist in datasource) then you should return a 404. SimpleWeb doesn't have a Status.NotFound but has Status.NoContent (204).

Could you share your wisdom behind which code should be returned for the scenario mentioned above, or any other you may have?

Many Thanks

Simple.Web.AspNet broken?

  1. Asp.net empty web app
  2. Add Reference
  3. Simple.Web.AspNet
    adds this to web.config



    among other stuff
  4. Run
    Server application error: Could not load type 'Simple.Web.AspNet.SimpleHttpAsyncHandler'.

If I removed that I get the directory listing page. Am I missing something?

Improved Razor support

Improve Razor View Engine support for;

  • Layouts
  • Partials
  • Sections

Provide guidance on;

  • IntelliSense in Visual Studio

Consider future support for;

  • Templated helpers (or similar - HTML builder methods)
  • URL helpers (with consideration to deriving routes)

IOutput<RawHTML> doesn't work on Mono

This isn't working on Mono because the IOutputBehaviours scanning isn't picking it up so it defaults to trying to find an appropriate media-type handler. Going to take a deeper look at this as not sure current implementation is most performant either.

POST/PUTing F# Records

It would be helpful if F# records were available for use in IPost and IPut (and any other places where the incoming model binding is fired). Currently they cause a 500 to be sent to the client and it takes a bit of digging to figure out what is going on and that the record is causing the pipeline to blow up.

Simple.Owin thoughts

I have been thinking more about separating Simple.Web.OwinSupport out into Simple.Owin to support more consistent and faster development of Simple.Owin.* middleware.

As you mentioned earlier @markrendle, there is the possibility of Simple.Owin to be a single file source include. All of the classes in Simple.Web.OwinSupport being internal are good for this, but then there are the 3 core interfaces (IContext, IRequest, IResponse) and the helper interface (IPostedFile) which are public. Having these interfaces public, and defined in multiple assemblies will lead us into a pit of failure.

Other things that I think would be beneficial in Simple.Owin are the extension classes for the interface above, as well as the rest of the basic http support in Simple.Web.Http. And to support authentication in middleware, it would be helpful to have IUser defined.

Route matching could be brought in as well, but could just as easily be added independently in each middleware.

At the same time, we should also look at moving Simple.Web.Mocks to Simple.Owin.Mocks

Your thoughts?

404 vs 204

Hi Mark,

Sorry if log this as issue because it isn't, but 140 chars on twitter won't be enough for me to ask my question.

I'm not an expert in rest but I have always been under the impression that if the system doesn't find a resource given an id (resource doesnt exist in datasource) then you should return a 404. SimpleWeb doesn't have a Status.NotFound but has Status.NoContent (204).

Could you share your wisdom behind which code should be returned for the scenario mentioned above, or any other you may have?

Many Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.