nancyfx / nancy.bootstrappers.structuremap Goto Github PK
View Code? Open in Web Editor NEWNancy bootstrapper for the StructureMap container
License: MIT License
Nancy bootstrapper for the StructureMap container
License: MIT License
hi, we just migrated from 0.9 to 0.10 and we have a server error looking like this:
StructureMap Exception Code: 205
Missing requested Instance property "modulePath" for InstanceKey "Nancy.Testing.Fakes.FakeNancyModule"
On version 0.9 we fixed it by setting this:
container.Configure(x =>
{
x.SelectConstructor(() => new FakeNancyModule()); //Structuremap container fix
});
On version 0.10 we don't know how to fix it, and why is that line needed in version 0.9
There's a problem with how IRequestStartup
classes are handled in Windsor Bootstrapper.
When WindsorNancyBootstrapper.RegisterAndGetRequestStartupTasks
is called for the first time all is good. IRequestStartup
s are registered scoped to single request and then resolved.
However any further call to that method during subsequent requests fails with message "There is already a component with that name.".
I understand this can work like that in bootstrappers that create child containers, but given that with Windsor it's not implemented like that, there should be a guard of sorts.
This is an enhancement to docs. Having installed the latest NuGet packages for Nancy and StructureMapNancyBootstrapper, I've had a horrific day trying to get something basic working inside an existing project I could simply have used WebAPI for (specifically, being fairly new to Nancy and it's bootstrapper, I just want a tutorial showing a non-self-hosted setup using the StructureMap Bootstrapper, using an appropriate VS2013 template, for RESTful API endpoints - But I suspect such noobie issues are for SO not here, since nobody has blogged an end-to end with that specific scenario :)
What I'd really like is an end-to-end walk through for non-happy path stuff, since small scale, super-duper-happy-path stuff trades-off against the pain of working with existing legacy code (which is often far from a happy experience and there is naturally so much more of it, so I could argue that's the real 'happy path'). Indeed, copying and pasting the sample from the README.md into VS and I get the attached image indicating that no ApplicationStartup etc. methods exist to override. Has the boot-strapper not got these methods any more? Or perhaps I'm using the wrong IContainer?
So, after that rant, would it be too much to ask to include the using statements as part of the sample?
In packages.config;
<package id="Nancy.Bootstrappers.StructureMap" version="0.20.0" targetFramework="net45" />
Project reference is lowercase as per nuspec id;
<HintPath>..\packages\Nancy.Bootstrappers.StructureMap.0.20.0\lib\net40\Nancy.Bootstrappers.StructureMap.dll</HintPath>
BUT the physical directory is not;
Which means the build fails on (case-sensitive) Mono.
To fix this you usually need to ask the wonderful @jeffhandley to do some voodoo on the nuget server (e.g. Particular/NServiceBus#1271).
Since Unix is actually case sensitive on the folder name it expects the package in the folder "Nancy.Bootstrappers.StructureMap" but since the nupkg file is named "Nancy.BootStrappers.StructureMap" it extracts the package to the directory with upper case "S" in BootStrappers which causes this problem. This is a naming error in the first place and should be fixed at least with the next version! All other Bootstrapper plugins are fine, just this one is not compatible on any platform with case sensitive folder and filenames
after upgrade to 0.22.2 the virtual methods described in the read me-file does not exist (ConfigureApplicationContainer, ConfigureRequestContainer, RequestStartup and GetApplicationContainer)? Please update the read me file? Or am I missing something?
Hi everyone, please excuse complete ignorance on how to properly use Github/report issues, and I don't feel confident that my code is good enough to do a pull request (if I could figure out how!!)
Anyway, I upgraded from 0.23 to 1.1 and my external Module, that implemented IRequestStartup wasn't being called anymore.
My code change to fix was:
In this RegisterAndGetRequestStartupTasks function, it appeared like the types weren't actually being registered, so I added:
container.Configure(registry => {
foreach (var requestStartupType in requestStartupTypes) {
registry.For(typeof(IRequestStartup)).LifecycleIs(Lifecycles.Unique).Use(requestStartupType);
}
});
Thanks for being patient with the bad way to get issues reported/code fixes in,
Stephen
Structuremap 4.1.0.318
Nancy 1.4.3
using (var host = new NancyHost(uri, new Bootstrapper(), hostConfigs))
Could not load type 'StructureMap.Configuration.DSL.Registry' from assembly 'StructureMap, Version=4.0.1.318, Culture=neutral, PublicKeyToken=null'.
at Nancy.Bootstrappers.StructureMap.StructureMapNancyBootstrapper.b__0(ConfigurationExpression registry)
at StructureMap.PipelineGraph.Configure(Action1 configure) in C:\BuildAgent\work\a395dbde6b793293\src\StructureMap.Shared\PipelineGraph.cs:line 170 at StructureMap.Container.Configure(Action
1 configure) in C:\BuildAgent\work\a395dbde6b793293\src\StructureMap.Shared\Container.cs:line 806
at Nancy.Bootstrappers.StructureMap.StructureMapNancyBootstrapper.RegisterBootstrapperTypes(IContainer applicationContainer)
at Nancy.Bootstrapper.NancyBootstrapperBase`1.Initialise()
at Nancy.Hosting.Self.NancyHost..ctor(INancyBootstrapper bootstrapper, HostConfiguration configuration, Uri[] baseUris)
at Nancy.Hosting.Self.NancyHost..ctor(Uri baseUri, INancyBootstrapper bootstrapper, HostConfiguration configuration)
at Api.Push.ManagementInterface.Nancy.EntryPoint.Main(String[] args) in C:\Projects\api-push\src\Api.Push\ManagementInterface\Api.Push.ManagementInterface.Nancy\EntryPoint.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
A clean install of Nancy, Nancy-aspnet, Nancy-razor and Nancy-structuremap seems to have a problem with adding the DefaultRazorConfiguration to the container. On app start-up, you're presented with the following error:
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily Nancy.ViewEngines.Razor.IRazorConfiguration, Nancy.ViewEngines.Razor, Version=0.9.0.0, Culture=neutral, PublicKeyToken=null
I've uploaded a sample solution to http://www.rasmuskl.dk/NancySMTest.zip
After upgrading to v0.23 of the StructureMap Bootstrapper we've begun to notice an issue when making concurrent requests to NancyFx powered services.
Every now and then NullReferenceExceptions occur when the service tries to resolve the requested INancyModule from the StructureMap container. The issue does not occur in v0.22.2.
Example stack trace
StructureMap.Building.StructureMapBuildException: Error while building type Modules.StatusEndpoint.StatusModule. See the inner exception for details
1.) new StatusModule(Enumerable of Modules.StatusEndpoint.IStatusReporter with all registered instances)
2.) Modules.StatusEndpoint.StatusModule
3.) Instance of Nancy.INancyModule (Modules.StatusEndpoint.StatusModule)
4.) Container.GetInstance(Nancy.INancyModule)
5.) Container.TryGetInstance(Nancy.INancyModule)
---> System.NullReferenceException: Object reference not set to an instance of an object.
at StructureMap.BuildSession.BuildNewInSession(Type pluginType, Instance instance) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\BuildSession.cs:line 107
at StructureMap.Pipeline.LifecycleObjectCache.Get(Type pluginType, Instance instance, IBuildSession session) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Pipeline\LifecycleObjectCache.cs:line 60
at StructureMap.SessionCache.GetObject(Type pluginType, Instance instance, ILifecycle lifecycle) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\SessionCache.cs:line 88
at StructureMap.BuildSession.<GetAllInstances>b__3[T](Instance x) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\BuildSession.cs:line 121
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at StructureMap.BuildSession.GetAllInstances[T]() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\BuildSession.cs:line 119
at lambda_method(Closure , IBuildSession , IContext )
--- End of inner exception stack trace ---
at lambda_method(Closure , IBuildSession , IContext )
at StructureMap.Building.BuildPlan.Build(IBuildSession session, IContext context) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Building\BuildPlan.cs:line 153
at StructureMap.SessionCache.GetDefault(Type pluginType, IPipelineGraph pipelineGraph) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\SessionCache.cs:line 68
at StructureMap.Container.GetInstance(Type pluginType) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Container.cs:line 325
at StructureMap.Container.TryGetInstance(Type pluginType) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Container.cs:line 268
at StructureMap.Container.TryGetInstance[T]() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Container.cs:line 277
at Nancy.Routing.DefaultRouteResolver.BuildResult(NancyContext context, MatchResult result)
at Modules.NewRelicStartup.<Initialize>b__0(NancyContext context) in c:\BuildAgent\work\fc461108b638e316\src\Modules\NewRelicStartup.cs:line 21
at Nancy.BeforePipeline.<>c__DisplayClass4.<Wrap>b__3(NancyContext ctx, CancellationToken ct)
As the error is being thrown from within StructureMap, it could be a problem within v3.0.1.114. So I will add an issue there too.
We've experience it across 2 separate applications, so were wondering if anyone else had seen it too.
I'm trying to use the StructureMapNancyBootstrapper with my unit tests. But I get an exception when I try to instantiate the Browser. See this SO question for more information: http://stackoverflow.com/questions/8139966/nancy-test-fails-because-of-missing-modulepath-for-fakenancymodule
I've created an example project here: https://github.com/jvandertil/NancyStructureMapSelfHostBug
Steps to reproduce:
Removing the custom bootstrapper makes the StackOverflowException go away. However the custom bootstrapper is simply this:
public class Bootstrapper : StructureMapNancyBootstrapper
{
}
I'll investigate for a bit, but I am not sure if I can find anything useful.
Obviously, it happens when the container is disposed. So that narrows it down a bit :)
applicationContainer.Configure(registry => registry.For<INancyModuleCatalog>().Singleton().Use(this));
This raised a mental red flag for me, as it might cause recursive disposal.
Appears it may be a SM3 bug.
Running the test Should_be_able_to_resolve_engine():
StructureMap.StructureMapConfigurationException
No default Instance is registered and cannot be automatically determined for type 'Nancy.Tests.Fakes.IFoo'
There is no configuration specified for Nancy.Tests.Fakes.IFoo
1.) new Dependency(*Default of IFoo*)
2.) Nancy.Tests.Fakes.Dependency
3.) Instance of Nancy.Tests.Fakes.IDependency (Nancy.Tests.Fakes.Dependency)
4.) new FakeNancyModuleWithDependency(*Default of IDependency*, *Default of IFoo*)
5.) Nancy.Tests.Fakes.FakeNancyModuleWithDependency
6.) Instance of Nancy.INancyModule (Nancy.Tests.Fakes.FakeNancyModuleWithDependency)
7.) Container.GetAllInstances<Nancy.INancyModule>()
8.) new RouteCache(*Default of INancyModuleCatalog*, *Default of INancyContextFactory*, *Default of IRouteSegmentExtractor*, *Default of IRouteDescriptionProvider*, *Default of ICultureService*, Enumerable of Nancy.Routing.IRouteMetadataProvider with all registered instances)
9.) Nancy.Routing.RouteCache
10.) Instance of Nancy.Routing.IRouteCache (Nancy.Routing.RouteCache)
11.) new DefaultRouteResolver(*Default of INancyModuleCatalog*, *Default of INancyModuleBuilder*, *Default of IRouteCache*, *Default of IRouteResolverTrie*)
12.) Nancy.Routing.DefaultRouteResolver
13.) Instance of Nancy.Routing.IRouteResolver (Nancy.Routing.DefaultRouteResolver)
14.) new DefaultRequestDispatcher(*Default of IRouteResolver*, Enumerable of Nancy.Responses.Negotiation.IResponseProcessor with all registered instances, *Default of IRouteInvoker*)
15.) Nancy.Routing.DefaultRequestDispatcher
16.) Instance of Nancy.Routing.IRequestDispatcher (Nancy.Routing.DefaultRequestDispatcher)
17.) new NancyEngine(*Default of IRequestDispatcher*, *Default of INancyContextFactory*, Enumerable of Nancy.ErrorHandling.IStatusCodeHandler with all registered instances, *Default of IRequestTracing*, *Default of DiagnosticsConfiguration*, *Default of IStaticContentProvider*)
18.) Nancy.NancyEngine
19.) Instance of Nancy.INancyEngine (Nancy.NancyEngine)
20.) Container.GetInstance(Nancy.INancyEngine)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.