Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 0be9a4c8f2218399a30dde956134ac1dbe60313a @digitalBush committed
19 .gitignore
@@ -0,0 +1,19 @@
+build/
+reports/
+[Bb]in/
+[Oo]bj/
+TestResults/
+PrecompiledWeb/
+src/CommonAssemblyInfo.cs
+artifacts
+lib
+*.gpState
+*.suo
+*.user
+*[Rr]e[Ss]harper*
+*.cache
+UpgradeLog.XML
+_UpgradeReport_Files/
+*.bak
+*.log
+*.log.*
26 Autofac.Settings.sln
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Autofac.Settings", "src\Autofac.Settings\Autofac.Settings.csproj", "{EF1587DD-B120-4D3F-ADAD-F54243C97730}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Autofac.Settings.Specs", "specs\Autofac.Settings.Specs\Autofac.Settings.Specs.csproj", "{A20C6CAC-A71B-4862-B8BD-046A21964FAC}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {EF1587DD-B120-4D3F-ADAD-F54243C97730}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EF1587DD-B120-4D3F-ADAD-F54243C97730}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EF1587DD-B120-4D3F-ADAD-F54243C97730}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EF1587DD-B120-4D3F-ADAD-F54243C97730}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A20C6CAC-A71B-4862-B8BD-046A21964FAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A20C6CAC-A71B-4862-B8BD-046A21964FAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A20C6CAC-A71B-4862-B8BD-046A21964FAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A20C6CAC-A71B-4862-B8BD-046A21964FAC}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
73 specs/Autofac.Settings.Specs/Autofac.Settings.Specs.csproj
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{A20C6CAC-A71B-4862-B8BD-046A21964FAC}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Autofac.Settings.Specs</RootNamespace>
+ <AssemblyName>Autofac.Settings.Specs</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Autofac">
+ <HintPath>..\..\lib\Autofac\lib\NET40\Autofac.dll</HintPath>
+ </Reference>
+ <Reference Include="Machine.Specifications">
+ <HintPath>..\..\lib\Machine.Specifications\lib\Machine.Specifications.dll</HintPath>
+ </Reference>
+ <Reference Include="Moq">
+ <HintPath>..\..\lib\Moq\lib\NET40\Moq.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="NameValueSettingsProvider.specs.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ReflectionHelper.specs.cs" />
+ <Compile Include="SettingsFactory.specs.cs" />
+ <Compile Include="SettingsSource.specs.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\Autofac.Settings\Autofac.Settings.csproj">
+ <Project>{EF1587DD-B120-4D3F-ADAD-F54243C97730}</Project>
+ <Name>Autofac.Settings</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
67 specs/Autofac.Settings.Specs/NameValueSettingsProvider.specs.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Configuration;
+using Machine.Specifications;
+
+namespace Autofac.Settings.Specs {
+ [Subject(typeof (NameValueSettingsProvider))]
+ public class when_touching_object_with_primitive_properties {
+ static Settings _instance;
+ static NameValueSettingsProvider _provider;
+ static IEnumerable<string> _properties;
+
+ Establish context = () => {
+ _instance = new Settings();
+ _provider =
+ new NameValueSettingsProvider(new NameValueCollection {
+ {"Settings.Foo", "Yo"},
+ {"Settings.Bar", "42"},
+ {"Settings.Baz", "3.14"}
+ });
+ };
+
+ Because of = () => _properties = _provider.Touch(_instance);
+
+ It should_have_the_right_value_for_Bar_property = () => _instance.Bar.ShouldEqual(42);
+ It should_have_the_right_value_for_Baz_property = () => _instance.Baz.ShouldEqual(3.14m);
+ It should_have_the_right_value_for_Foo_property = () => _instance.Foo.ShouldEqual("Yo");
+ It should_have_touched_all_properties = () => _properties.ShouldContainOnly("Foo", "Bar", "Baz");
+
+ #region Nested type: Settings
+
+ class Settings {
+ public string Foo { get; set; }
+ public int Bar { get; set; }
+ public decimal Baz { get; set; }
+ }
+
+ #endregion
+ }
+
+ [Subject(typeof (NameValueSettingsProvider))]
+ public class when_setting_a_property_with_an_incorrect_name {
+ static Settings _instance;
+ static NameValueSettingsProvider _provider;
+ static Exception _exception;
+
+ Establish context = () => {
+ _instance = new Settings();
+ _provider =
+ new NameValueSettingsProvider(new NameValueCollection {{"Settings.No", "Bad"}});
+ };
+
+ Because of = () => _exception = Catch.Exception(() => _provider.Touch(_instance));
+
+ It should_report_the_invalid_configuration_item = () => _exception.Message.ShouldStartWith("\"No\"");
+ It should_throw_exception = () => _exception.ShouldBeOfType<ConfigurationErrorsException>();
+
+ #region Nested type: Settings
+
+ class Settings {
+ public string Foo { get; set; }
+ }
+
+ #endregion
+ }
+}
36 specs/Autofac.Settings.Specs/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Autofac.Settings.Specs")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Autofac.Settings.Specs")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("11db3907-5a90-4a38-b7b6-081ac2fba7b8")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
17 specs/Autofac.Settings.Specs/ReflectionHelper.specs.cs
@@ -0,0 +1,17 @@
+using Machine.Specifications;
+
+namespace Autofac.Settings.Specs {
+
+ [Subject(typeof(ReflectionHelper))]
+ public class when_setting_a_property_with_helper {
+ static Settings _settings;
+
+ Establish context = () => _settings = new Settings();
+ Because of = () => _settings.SetProperty("Test", "Foo");
+ It should_have_the_correct_value = () => _settings.Test.ShouldEqual("Foo");
+
+ class Settings {
+ public string Test { get; set; }
+ }
+ }
+}
92 specs/Autofac.Settings.Specs/SettingsFactory.specs.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using Machine.Specifications;
+using Moq;
+using Arg=Moq.It;
+using It = Machine.Specifications.It;
+
+
+namespace Autofac.Settings.Specs {
+
+
+ [Subject(typeof(SettingsFactory))]
+ public class when_creating_settings_where_all_properties_specified {
+ static Mock<ISettingsProvider> _provider;
+ static SettingsFactory _factory;
+ static object _settings;
+
+ Establish context = () => {
+ _provider = new Mock<ISettingsProvider>();
+ _provider.Setup(x => x.Touch(Arg.IsAny<object>())).Returns(new[] {"Foo", "Bar"}).Verifiable();
+ _factory=new SettingsFactory(new[]{_provider.Object});
+ };
+
+ Because of = () => _settings = _factory.Create(typeof (Settings));
+
+ It should_create_settings_object = () => _settings.ShouldNotBeNull();
+ It should_call_settings_provider = () => _provider.Verify();
+
+ class Settings {
+ public string Foo { get; set; }
+ public int Bar { get; set; }
+ }
+
+ }
+
+ [Subject(typeof(SettingsFactory))]
+ public class when_creating_settings_where_NOT_all_properties_specified {
+ static Mock<ISettingsProvider> _provider;
+ static SettingsFactory _factory;
+ static Exception _exception;
+
+ Establish context = () => {
+ _provider = new Mock<ISettingsProvider>();
+ _provider.Setup(x => x.Touch(Arg.IsAny<object>())).Returns(new[] { "Foo" }).Verifiable();
+ _factory = new SettingsFactory(new[] { _provider.Object });
+ };
+
+ Because of = () => _exception=Catch.Exception(()=> _factory.Create(typeof(Settings)));
+
+ It should_throw_configuration_errors_exception = () => _exception.ShouldBeOfType<ConfigurationErrorsException>();
+ It should_have_exception_message_with_missed_properties = () => _exception.Message.ShouldEndWith("Bar");
+ It should_call_settings_provider = () => _provider.Verify();
+
+ class Settings {
+ public string Foo { get; set; }
+ public int Bar { get; set; }
+ }
+
+ }
+
+ [Subject(typeof(SettingsFactory))]
+ public class when_creating_settings_from_multiple_providers {
+ static List<Mock<ISettingsProvider>> _providers;
+ static SettingsFactory _factory;
+ static object _settings;
+
+ Establish context = () => {
+ var p1 = new Mock<ISettingsProvider>();
+ p1.Setup(x => x.Touch(Arg.IsAny<object>())).Returns(new[] { "Foo" }).Verifiable();
+
+ var p2 = new Mock<ISettingsProvider>();
+ p2.Setup(x => x.Touch(Arg.IsAny<object>())).Returns(new[] { "Bar" }).Verifiable();
+
+ _providers=new List<Mock<ISettingsProvider>>(){p1,p2};
+
+ _factory = new SettingsFactory(_providers.Select(x=>x.Object));
+ };
+
+ Because of = () => _settings = _factory.Create(typeof(Settings));
+
+ It should_create_settings_object = () => _settings.ShouldNotBeNull();
+ It should_call_all_settings_provider = () => _providers.ForEach(x => x.Verify());
+
+ class Settings {
+ public string Foo { get; set; }
+ public int Bar { get; set; }
+ }
+
+ }
+}
43 specs/Autofac.Settings.Specs/SettingsSource.specs.cs
@@ -0,0 +1,43 @@
+using System.Collections.Specialized;
+using Machine.Specifications;
+
+namespace Autofac.Settings.Specs {
+
+ [Subject(typeof(SettingsSource))]
+ public class when_resolving_settings {
+
+ class FooSettings {
+ public string Bar { get; set; }
+ }
+
+ class NeedsSomeSettings {
+ public NeedsSomeSettings(FooSettings settings) {
+ Settings = settings;
+ }
+
+ public FooSettings Settings { get; private set; }
+ }
+
+
+ static IContainer _container;
+ static NeedsSomeSettings _needsomeSettings;
+
+
+ Establish context = ()=> {
+ var builder = new ContainerBuilder();
+ builder.RegisterSource(new SettingsSource());
+ builder.RegisterType<SettingsFactory>().AsImplementedInterfaces();
+ builder.RegisterType<NameValueSettingsProvider>()
+ .WithParameter("source", new NameValueCollection() {{"FooSettings.Bar", "w00t!"}})
+ .AsImplementedInterfaces();
+ builder.RegisterType<NeedsSomeSettings>().AsSelf();
+ _container = builder.Build();
+ };
+
+ Because of = () => _needsomeSettings = _container.Resolve<NeedsSomeSettings>();
+
+ It should_resolve_type = () => _needsomeSettings.ShouldNotBeNull();
+ It should_have_settings = () => _needsomeSettings.Settings.ShouldNotBeNull();
+ It should_have_settings_populated = () => _needsomeSettings.Settings.Bar.ShouldEqual("w00t!");
+ }
+}
7 src/Autofac.Settings/AppConfigSettingsProvider.cs
@@ -0,0 +1,7 @@
+using System.Configuration;
+
+namespace Autofac.Settings {
+ public class AppConfigSettingsProvider : NameValueSettingsProvider {
+ public AppConfigSettingsProvider() : base(ConfigurationManager.AppSettings) { }
+ }
+}
64 src/Autofac.Settings/Autofac.Settings.csproj
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{EF1587DD-B120-4D3F-ADAD-F54243C97730}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Autofac.Settings</RootNamespace>
+ <AssemblyName>Autofac.Settings</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Autofac">
+ <HintPath>..\..\lib\Autofac\lib\NET40\Autofac.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AppConfigSettingsProvider.cs" />
+ <Compile Include="SettingsSource.cs" />
+ <Compile Include="ISettingsFactory.cs" />
+ <Compile Include="ISettingsProvider.cs" />
+ <Compile Include="NameValueSettingsProvider.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="ReflectionHelper.cs" />
+ <Compile Include="SettingsFactory.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
7 src/Autofac.Settings/ISettingsFactory.cs
@@ -0,0 +1,7 @@
+using System;
+
+namespace Autofac.Settings {
+ public interface ISettingsFactory {
+ object Create(Type type);
+ }
+}
7 src/Autofac.Settings/ISettingsProvider.cs
@@ -0,0 +1,7 @@
+using System.Collections.Generic;
+
+namespace Autofac.Settings {
+ public interface ISettingsProvider {
+ IEnumerable<string> Touch(object obj);
+ }
+}
28 src/Autofac.Settings/NameValueSettingsProvider.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Linq;
+
+namespace Autofac.Settings {
+ public class NameValueSettingsProvider : ISettingsProvider {
+ private readonly NameValueCollection _source;
+
+ public NameValueSettingsProvider(NameValueCollection source) {
+ _source = source;
+ }
+
+ public IEnumerable<string> Touch(object obj)
+ {
+ List<string> propsTouched=new List<string>();
+ Type type = obj.GetType();
+ var keys=_source.AllKeys.Where(k => k.StartsWith(type.Name));
+ foreach (var key in keys)
+ {
+ var propName = key.Substring(type.Name.Length+1);
+ obj.SetProperty(propName,_source[key]);
+ propsTouched.Add(propName);
+ }
+ return propsTouched;
+ }
+ }
+}
36 src/Autofac.Settings/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Autofac.Settings")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Autofac.Settings")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("3d28071c-5d58-4292-9d0a-531c694d7ec9")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
19 src/Autofac.Settings/ReflectionHelper.cs
@@ -0,0 +1,19 @@
+using System;
+using System.ComponentModel;
+using System.Configuration;
+
+namespace Autofac.Settings {
+ public static class ReflectionHelper
+ {
+ public static void SetProperty(this object obj,string propertyName,object value)
+ {
+ var type = obj.GetType();
+ var prop=type.GetProperty(propertyName);
+ if(prop==null)
+ throw new ConfigurationErrorsException(String.Format("\"{0}\" is not a valid property for {1}",propertyName,type.Name));
+ var converter = TypeDescriptor.GetConverter(prop.PropertyType);
+ var newValue = converter.ConvertFrom(value);
+ prop.SetValue(obj, newValue, null);
+ }
+ }
+}
40 src/Autofac.Settings/SettingsFactory.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Reflection;
+
+namespace Autofac.Settings {
+ public class SettingsFactory : ISettingsFactory {
+ readonly IEnumerable<ISettingsProvider> _providers;
+
+ public SettingsFactory(IEnumerable<ISettingsProvider> providers) {
+ _providers = providers;
+ }
+
+ public object Create(Type type) {
+ var obj = Activator.CreateInstance(type);
+ var propertiesTouched = new HashSet<string>();
+ foreach (var provider in _providers) {
+ var touched = provider.Touch(obj);
+ propertiesTouched.UnionWith(touched);
+ }
+ VerifyAllPropertiesGotTouched(type, propertiesTouched);
+ return obj;
+ }
+
+ static void VerifyAllPropertiesGotTouched(Type type, HashSet<string> properties) {
+ var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
+ .Where(p => p.CanWrite)
+ .Select(p => p.Name)
+ .ToList();
+
+ var propertiesMissed = props.Except(properties);
+
+ if (propertiesMissed.Any()) {
+ var message = String.Format("{0} is missing the following properties in configuration: {1}", type.Name, String.Join(",", propertiesMissed));
+ throw new ConfigurationErrorsException(message);
+ }
+ }
+ }
+}
22 src/Autofac.Settings/SettingsSource.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using Autofac.Builder;
+using Autofac.Core;
+
+namespace Autofac.Settings {
+ public class SettingsSource : IRegistrationSource {
+ public IEnumerable<IComponentRegistration> RegistrationsFor(Service service, Func<Service, IEnumerable<IComponentRegistration>> registrationAccessor) {
+ var s = service as IServiceWithType;
+ if (s != null && s.ServiceType.IsClass && s.ServiceType.Name.EndsWith("Settings")) {
+ yield return RegistrationBuilder.ForDelegate((c, p) => c.Resolve<ISettingsFactory>().Create(s.ServiceType))
+ .As(s.ServiceType)
+ .SingleInstance()
+ .CreateRegistration();
+ }
+ }
+
+ public bool IsAdapterForIndividualComponents {
+ get { return false; }
+ }
+ }
+}
BIN tools/nuget/nuget.exe
Binary file not shown.

0 comments on commit 0be9a4c

Please sign in to comment.
Something went wrong with that request. Please try again.