Skip to content

Added ApplicationRegistrations base class #959

Merged
merged 6 commits into from Feb 11, 2013

2 participants

@thecodejunkie
Custodians of the Super-Duper-Happy-Path member

Can be used to register application dependencies, with fallbacks and order

@grumpydev grumpydev commented on the diff Feb 8, 2013
src/Nancy/Bootstrapper/ApplicationRegistrations.cs
+ /// Gets the type registrations to register for this startup task
+ /// </summary>
+ public IEnumerable<TypeRegistration> TypeRegistrations
+ {
+ get { return this.typeRegistrations; }
+ }
+
+ /// <summary>
+ /// Scans for the implementation of <typeparamref name="T"/> and registers it.
+ /// </summary>
+ /// <typeparam name="TRegistration">The <see cref="Type"/> to scan for and register as.</typeparam>
+ public void Register<TRegistration>()
+ {
+ var implementation = AppDomainAssemblyTypeScanner
+ .TypesOf<TRegistration>()
+ .Single();
@grumpydev
Custodians of the Super-Duper-Happy-Path member
grumpydev added a note Feb 8, 2013

Do we actually want to blow up here if there's more than one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@grumpydev grumpydev commented on the diff Feb 8, 2013
src/Nancy/Bootstrapper/ApplicationRegistrations.cs
@@ -0,0 +1,176 @@
+namespace Nancy.Bootstrapper
+{
+ using System;
@grumpydev
Custodians of the Super-Duper-Happy-Path member
grumpydev added a note Feb 8, 2013

Using statements should be inside the namespace ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@grumpydev grumpydev commented on the diff Feb 8, 2013
src/Nancy/Bootstrapper/ApplicationRegistrations.cs
+ var implementation = AppDomainAssemblyTypeScanner
+ .TypesOf<TRegistration>()
+ .Single();
+
+ this.typeRegistrations.Add(new TypeRegistration(typeof(TRegistration), implementation));
+ }
+
+ /// <summary>
+ /// Registers the types provided by the <paramref name="defaultImplementations"/> parameters
+ /// as <typeparamref name="TRegistration"/>.
+ /// </summary>
+ /// <typeparam name="TRegistration">The <see cref="Type"/> to register as.</typeparam>
+ /// <param name="defaultImplementations">The types to register.</param>
+ public void Register<TRegistration>(IEnumerable<Type> defaultImplementations)
+ {
+ this.collectionRegistrations.Add(new CollectionTypeRegistration(typeof(TRegistration), defaultImplementations));
@grumpydev
Custodians of the Super-Duper-Happy-Path member
grumpydev added a note Feb 8, 2013

Add a check that all types are actually implementations of TRegistration? OR maybe add that code to CollectionTypeRegistration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@grumpydev grumpydev commented on the diff Feb 8, 2013
src/Nancy/Bootstrapper/ApplicationRegistrations.cs
+ /// <typeparam name="TRegistration">The <see cref="Type"/> to register as.</typeparam>
+ /// <param name="defaultImplementations">The types to register.</param>
+ public void Register<TRegistration>(IEnumerable<Type> defaultImplementations)
+ {
+ this.collectionRegistrations.Add(new CollectionTypeRegistration(typeof(TRegistration), defaultImplementations));
+ }
+
+ /// <summary>
+ /// Registers the type provided by the <paramref name="implementation"/> parameter
+ /// as <typeparamref name="TRegistration"/>.
+ /// </summary>
+ /// <typeparam name="TRegistration">The <see cref="Type"/> to register as.</typeparam>
+ /// <param name="implementation">The <see cref="Type"/> to register as <typeparamref name="TRegistration"/>.</param>
+ public void Register<TRegistration>(Type implementation)
+ {
+ this.typeRegistrations.Add(new TypeRegistration(typeof(TRegistration), implementation));
@grumpydev
Custodians of the Super-Duper-Happy-Path member
grumpydev added a note Feb 8, 2013

Ditto with the checks on other types of registrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@grumpydev grumpydev commented on an outdated diff Feb 8, 2013
src/Nancy/Bootstrapper/ApplicationRegistrations.cs
+ this.typeRegistrations.Add(new TypeRegistration(typeof(TRegistration), implementation));
+ }
+
+ /// <summary>
+ /// Registers an instance as <typeparamref name="TRegistration"/>.
+ /// </summary>
+ /// <typeparam name="TRegistration">The <see cref="Type"/> to register as.</typeparam>
+ /// <param name="instance">The instance to register.</param>
+ public void Register<TRegistration>(TRegistration instance)
+ {
+ this.instanceRegistrations.Add(new InstanceRegistration(typeof(TRegistration), instance));
+ }
+
+ /// <summary>
+ /// Scans for a <see cref="Type"/> that implements <typeparamref name="TRegistration"/>. If found, then it
+ /// will be used for the registartion, else it will use <paramref name="defaultImplementation"/>.
@grumpydev
Custodians of the Super-Duper-Happy-Path member
grumpydev added a note Feb 8, 2013

Typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@thecodejunkie thecodejunkie merged commit 4b28703 into NancyFx:master Feb 11, 2013

1 check passed

Details default The Travis build passed
@thecodejunkie thecodejunkie deleted the thecodejunkie:applicationregistationsbase branch Feb 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.