Initial import!
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.IocQuickStart.MovieFinder.2003", "src/Spring.IocQuickStart.MovieFinder.2003.csproj", "{C261D9ED-85C3-4B35-BE48-7156F5B17430}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
Debug = Debug
|
||||
Release = Release
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Debug.ActiveCfg = Debug|.NET
|
||||
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Debug.Build.0 = Debug|.NET
|
||||
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Release.ActiveCfg = Release|.NET
|
||||
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Release.Build.0 = Release|.NET
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,19 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.IocQuickStart.MovieFinder.2005", "src/Spring.IocQuickStart.MovieFinder.2005.csproj", "{C261D9ED-85C3-4B35-BE48-7156F5B17430}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" ?>
|
||||
<project name="Spring.IocQuickStart.MovieFinder" default="build" xmlns="http://nant.sf.net/schemas/nant.xsd">
|
||||
<!--
|
||||
Required properties:
|
||||
* current.bin.dir - (path) root level to build to
|
||||
* current.build.debug - (true|false) debug build?
|
||||
* current.build.defines.csc - framework-specific build defines for C# compiler
|
||||
-->
|
||||
|
||||
<target name="build">
|
||||
<!-- build MovieFinder -->
|
||||
<csc target="exe"
|
||||
define="${current.build.defines.csc}"
|
||||
warnaserror="true"
|
||||
debug="${current.build.debug}"
|
||||
output="${current.bin.dir}/${project::get-name()}.exe">
|
||||
<sources failonempty="true">
|
||||
<include name="**/*.cs" />
|
||||
</sources>
|
||||
<resources prefix="Spring.IocQuickStart.MovieFinder" dynamicprefix="false" failonempty="true">
|
||||
<include name="**/*.xml" />
|
||||
</resources>
|
||||
<nowarn>
|
||||
<warning number="${nowarn.numbers}" />
|
||||
</nowarn>
|
||||
<references basedir="${current.bin.dir}">
|
||||
<include name="log4net.dll" />
|
||||
<include name="Common.Logging.dll"/>
|
||||
<include name="Common.Logging.Log4Net.dll"/>
|
||||
<include name="Spring.Core.dll" />
|
||||
</references>
|
||||
</csc>
|
||||
<copy tofile="${current.bin.dir}/${project::get-name()}.exe.config"
|
||||
file="src/App.config" overwrite="true">
|
||||
</copy>
|
||||
<copy todir="${current.bin.dir}"
|
||||
overwrite="true"
|
||||
flatten="true">
|
||||
<fileset basedir=".">
|
||||
<include name="**/movies.txt"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
</project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
|
||||
<configSections>
|
||||
<sectionGroup name="common">
|
||||
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
|
||||
</sectionGroup>
|
||||
<sectionGroup name="spring">
|
||||
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
|
||||
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
|
||||
</sectionGroup>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
|
||||
</configSections>
|
||||
|
||||
<common>
|
||||
<logging>
|
||||
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
|
||||
<!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
|
||||
<!-- otherwise BasicConfigurer.Configure is used -->
|
||||
<!-- log4net configuration file is specified with key configFile-->
|
||||
<arg key="configType" value="INLINE" />
|
||||
</factoryAdapter>
|
||||
</logging>
|
||||
</common>
|
||||
|
||||
<spring>
|
||||
|
||||
<context>
|
||||
<!-- using embedded assembly configuration file
|
||||
<resource uri="assembly://Spring.IocQuickStart.MovieFinder/Spring.IocQuickStart.MovieFinder/AppContext.xml"/>
|
||||
-->
|
||||
|
||||
<!-- using section in App.config -->
|
||||
<resource uri="config://spring/objects"/>
|
||||
|
||||
</context>
|
||||
|
||||
<objects xmlns="http://www.springframework.net" >
|
||||
<description>An example that demonstrates simple IoC features.</description>
|
||||
|
||||
<object id="MyMovieLister"
|
||||
type="Spring.IocQuickStart.MovieFinder.MovieLister, Spring.IocQuickStart.MovieFinder">
|
||||
<property name="MovieFinder" ref="AnotherMovieFinder"/>
|
||||
</object>
|
||||
|
||||
<!-- An IMovieFinder implementation that uses harcoded values as it's movie source... -->
|
||||
<object id="MyMovieFinder"
|
||||
type="Spring.IocQuickStart.MovieFinder.SimpleMovieFinder, Spring.IocQuickStart.MovieFinder"/>
|
||||
|
||||
<!-- An IMovieFinder implementation that uses a text file as it's movie source... -->
|
||||
<object id="AnotherMovieFinder"
|
||||
type="Spring.IocQuickStart.MovieFinder.ColonDelimitedMovieFinder, Spring.IocQuickStart.MovieFinder">
|
||||
<constructor-arg index="0" value="movies.txt"/>
|
||||
</object>
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.RequiredAttributeObjectPostProcessor, Spring.Core"/>
|
||||
|
||||
</objects>
|
||||
|
||||
</spring>
|
||||
|
||||
<log4net>
|
||||
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%-5level - %message%newline" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Set default logging level to DEBUG -->
|
||||
<root>
|
||||
<level value="DEBUG" />
|
||||
<appender-ref ref="ConsoleAppender" />
|
||||
</root>
|
||||
|
||||
<!-- Set logging for MovieFinder to DEBUG -->
|
||||
<logger name="Spring.IocQuickStart.MovieFinder">
|
||||
<level value="DEBUG" />
|
||||
</logger>
|
||||
|
||||
<!-- Set logging for Spring to INFO.
|
||||
Logger names in Spring correspond to the namespace -->
|
||||
<logger name="Spring">
|
||||
<level value="INFO" />
|
||||
</logger>
|
||||
|
||||
</log4net>
|
||||
|
||||
</configuration>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net" >
|
||||
<description>An example that demonstrates simple IoC features.</description>
|
||||
|
||||
<object id="MyMovieLister"
|
||||
type="Spring.IocQuickStart.MovieFinder.MovieLister, Spring.IocQuickStart.MovieFinder">
|
||||
<property name="MovieFinder" ref="AnotherMovieFinder"/>
|
||||
</object>
|
||||
|
||||
|
||||
<!-- An IMovieFinder implementation that uses harcoded values as it's movie source... -->
|
||||
<!--
|
||||
<object id="MyMovieFinder"
|
||||
type="Spring.IocQuickStart.MovieFinder.SimpleMovieFinder, Spring.IocQuickStart.MovieFinder"/>
|
||||
-->
|
||||
|
||||
|
||||
<!--An IMovieFinder implementation that uses a text file as it's movie source... -->
|
||||
|
||||
<object id="AnotherMovieFinder"
|
||||
type="Spring.IocQuickStart.MovieFinder.ColonDelimitedMovieFinder, Spring.IocQuickStart.MovieFinder">
|
||||
<constructor-arg index="0" value="movies.txt"/>
|
||||
</object>
|
||||
|
||||
<object type="Spring.Objects.Factory.Attributes.RequiredAttributeObjectPostProcessor, Spring.Core"/>
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net" >
|
||||
<description>An example that demonstrates contributing on implementation of MovieFinder progammatically.</description>
|
||||
|
||||
|
||||
<object id="MyMovieLister"
|
||||
type="Spring.IocQuickStart.MovieFinder.MovieLister, Spring.IocQuickStart.MovieFinder">
|
||||
<property name="movieFinder" ref="AnotherMovieFinder"/>
|
||||
</object>
|
||||
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,107 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.IocQuickStart.MovieFinder
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="Spring.IocQuickStart.MovieFinder.IMovieFinder"/> implementation
|
||||
/// that uses a colon delimited text file as it's backing data store.
|
||||
/// </summary>
|
||||
public class ColonDelimitedMovieFinder : IMovieFinder
|
||||
{
|
||||
private static readonly char [] Delimeter = new char [] {':'};
|
||||
|
||||
private FileInfo _movieFile;
|
||||
private IList _movies;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.ColonDelimitedMovieFinder"/> class.
|
||||
/// </summary>
|
||||
/// <param name="file">
|
||||
/// The file containing colon delimited movies.
|
||||
/// </param>
|
||||
public ColonDelimitedMovieFinder (FileInfo file)
|
||||
{
|
||||
MovieFile = file;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The file containing colon delimited movies.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="System.IO.FileInfo"/> pointing to the file containing
|
||||
/// colon delimited movies.
|
||||
/// </value>
|
||||
public FileInfo MovieFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return _movieFile;
|
||||
}
|
||||
set
|
||||
{
|
||||
_movieFile = value;
|
||||
if (_movieFile != null && _movieFile.Exists)
|
||||
{
|
||||
InitList ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds all of the movies stored in this
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.IMovieFinder"/> implementation.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// All of the movies stored in this
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.IMovieFinder"/> implementation.
|
||||
/// </returns>
|
||||
public IList FindAll ()
|
||||
{
|
||||
return _movies;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads all of the movies in the file referred to by <c>MovieFile</c>.
|
||||
/// </summary>
|
||||
private void InitList ()
|
||||
{
|
||||
_movies = new ArrayList ();
|
||||
using (StreamReader reader = MovieFile.OpenText ())
|
||||
{
|
||||
string line = null;
|
||||
while ((line = reader.ReadLine ()) != null)
|
||||
{
|
||||
string [] tuple = line.Split (Delimeter);
|
||||
Movie movie = new Movie (tuple [0], tuple [1]);
|
||||
_movies.Add (movie);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Collections;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.IocQuickStart.MovieFinder
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the interface for finding a list of movies independent of <i>how</i>
|
||||
/// said movies are actually stored (text file, database, etc).
|
||||
/// </summary>
|
||||
public interface IMovieFinder
|
||||
{
|
||||
/// <summary>Finds all of the stored movies.</summary>
|
||||
/// <returns>All of the stored movies.</returns>
|
||||
IList FindAll ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.IocQuickStart.MovieFinder
|
||||
{
|
||||
/// <summary>
|
||||
/// An object that describes a movie.
|
||||
/// </summary>
|
||||
public class Movie
|
||||
{
|
||||
private string _title;
|
||||
private string _director;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.Movie"/> class.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the movie.</param>
|
||||
/// <param name="director">The director of the movie.</param>
|
||||
public Movie (string title, string director)
|
||||
{
|
||||
_title = title;
|
||||
_director = director;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Property Title (string).
|
||||
/// </summary>
|
||||
public string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
set
|
||||
{
|
||||
_title = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Property Director (string).
|
||||
/// </summary>
|
||||
public string Director
|
||||
{
|
||||
get
|
||||
{
|
||||
return _director;
|
||||
}
|
||||
set
|
||||
{
|
||||
_director = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#region Licence
|
||||
|
||||
/*
|
||||
* Copyright 2002-2004 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Collections;
|
||||
using Spring.Objects.Factory.Attributes;
|
||||
|
||||
namespace Spring.IocQuickStart.MovieFinder
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that provides a list of movies directed by a particular director.
|
||||
/// </summary>
|
||||
public class MovieLister
|
||||
{
|
||||
private IMovieFinder _movieFinder;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.MovieLister"/> class.
|
||||
/// </summary>
|
||||
public MovieLister ()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Property MovieFinder (IMovieFinder).
|
||||
/// </summary>
|
||||
[Required]
|
||||
public IMovieFinder MovieFinder
|
||||
{
|
||||
get
|
||||
{
|
||||
return _movieFinder;
|
||||
}
|
||||
set
|
||||
{
|
||||
_movieFinder = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of those movies directed by the supplied
|
||||
/// <paramref name="director"/>
|
||||
/// </summary>
|
||||
/// <param name="director">
|
||||
/// The name of the director whose movies we are to return.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A list of those movies directed by the supplied
|
||||
/// <paramref name="director"/>.
|
||||
/// </returns>
|
||||
public Movie [] MoviesDirectedBy (string director)
|
||||
{
|
||||
IList allMovies = _movieFinder.FindAll ();
|
||||
IList movies = new ArrayList ();
|
||||
foreach (Movie m in allMovies)
|
||||
{
|
||||
if (director.Equals (m.Director))
|
||||
{
|
||||
movies.Add (m);
|
||||
}
|
||||
}
|
||||
return (Movie []) ArrayList.Adapter (movies).ToArray (typeof (Movie));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using Common.Logging;
|
||||
using Common.Logging.Log4Net;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects.Factory.Config;
|
||||
using Spring.Objects.Factory.Support;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.IocQuickStart.MovieFinder
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple application that demonstrates the IoC functionality of Spring.NET.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <p>
|
||||
/// See <a href="http://martinfowler.com/articles/injection.html"/> for the background
|
||||
/// article on which this example application is based.
|
||||
/// </p>
|
||||
/// </remarks>
|
||||
public sealed class Program
|
||||
{
|
||||
#region Logging Definition
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(Program));
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
try
|
||||
{
|
||||
IApplicationContext ctx = ContextRegistry.GetContext();
|
||||
|
||||
#region Advanced: Call alternative ways to create application context
|
||||
//CreateContextMixXmlAndProgrammatic();
|
||||
//CreateContextProgrammatically();
|
||||
//CreateContextProgrammaticallyWithAutoWire();
|
||||
#endregion
|
||||
|
||||
MovieLister lister = (MovieLister) ctx.GetObject("MyMovieLister");
|
||||
Movie[] movies = lister.MoviesDirectedBy("Roberto Benigni");
|
||||
LOG.Debug("Searching for movie...");
|
||||
foreach (Movie movie in movies)
|
||||
{
|
||||
LOG.Debug(
|
||||
string.Format("Movie Title = '{0}', Director = '{1}'.",
|
||||
movie.Title, movie.Director));
|
||||
}
|
||||
LOG.Debug("MovieApp Done.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOG.Error("Movie Finder is broken.", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("--- hit <return> to quit ---");
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Implementation of alternative ways to create application context
|
||||
|
||||
private static IApplicationContext CreateContextProgrammatically()
|
||||
{
|
||||
InitializeCommonLogging();
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
|
||||
IObjectDefinitionFactory objectDefinitionFactory = new DefaultObjectDefinitionFactory();
|
||||
|
||||
|
||||
//Create MovieLister and dependency on
|
||||
ObjectDefinitionBuilder builder =
|
||||
ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(MovieLister));
|
||||
builder.AddPropertyReference("MovieFinder", "AnotherMovieFinder");
|
||||
|
||||
ctx.RegisterObjectDefinition("MyMovieLister", builder.ObjectDefinition);
|
||||
|
||||
builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(ColonDelimitedMovieFinder));
|
||||
builder.AddConstructorArg("movies.txt");
|
||||
ctx.RegisterObjectDefinition("AnotherMovieFinder", builder.ObjectDefinition);
|
||||
|
||||
ctx.Refresh();
|
||||
|
||||
return ctx;
|
||||
|
||||
}
|
||||
|
||||
private static IApplicationContext CreateContextProgrammaticallyWithAutoWire()
|
||||
{
|
||||
InitializeCommonLogging();
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
|
||||
IObjectDefinitionFactory objectDefinitionFactory = new DefaultObjectDefinitionFactory();
|
||||
|
||||
|
||||
//Create MovieLister and dependency on
|
||||
ObjectDefinitionBuilder builder =
|
||||
ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(MovieLister));
|
||||
builder.AddPropertyReference("MovieFinder", "BogusNameOfDependency")
|
||||
.SetAutowireMode(AutoWiringMode.ByType);
|
||||
|
||||
ctx.RegisterObjectDefinition("MyMovieLister", builder.ObjectDefinition);
|
||||
|
||||
builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(ColonDelimitedMovieFinder));
|
||||
builder.AddConstructorArg("movies.txt")
|
||||
.SetAutowireMode(AutoWiringMode.ByType);
|
||||
|
||||
ctx.RegisterObjectDefinition("AnotherMovieFinder", builder.ObjectDefinition);
|
||||
|
||||
ctx.Refresh();
|
||||
|
||||
return ctx;
|
||||
|
||||
}
|
||||
|
||||
private static IApplicationContext CreateContextMixXmlAndProgrammatic()
|
||||
{
|
||||
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
|
||||
IObjectDefinitionReader objectDefinitionReader = new XmlObjectDefinitionReader(ctx);
|
||||
objectDefinitionReader.LoadObjectDefinitions("assembly://Spring.IocQuickStart.MovieFinder/Spring.IocQuickStart.MovieFinder/AppContextContribution.xml");
|
||||
|
||||
IObjectDefinitionFactory objectDefinitionFactory = new DefaultObjectDefinitionFactory();
|
||||
ObjectDefinitionBuilder builder =
|
||||
ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(ColonDelimitedMovieFinder));
|
||||
builder.AddConstructorArg("movies.txt");
|
||||
ctx.RegisterObjectDefinition("AnotherMovieFinder", builder.ObjectDefinition);
|
||||
|
||||
|
||||
ctx.Refresh();
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
private static void InitializeCommonLogging()
|
||||
{
|
||||
NameValueCollection properties = new NameValueCollection();
|
||||
properties["configType"] = "INLINE";
|
||||
LogManager.Adapter = new Log4NetLoggerFactoryAdapter(properties);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Collections;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.IocQuickStart.MovieFinder
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple in-memory storage implementation of the
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.IMovieFinder"/> interface.
|
||||
/// </summary>
|
||||
public class SimpleMovieFinder : IMovieFinder
|
||||
{
|
||||
private ArrayList _list = new ArrayList();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.SimpleMovieFinder"/> class.
|
||||
/// </summary>
|
||||
public SimpleMovieFinder()
|
||||
{
|
||||
InitList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a movie to the list.
|
||||
/// </summary>
|
||||
/// <param name="m">The movie.</param>
|
||||
public void AddMovie (Movie m)
|
||||
{
|
||||
_list.Add(m);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds all of the movies stored in this
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.IMovieFinder"/> implementation.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// All of the movies stored in this
|
||||
/// <see cref="Spring.IocQuickStart.MovieFinder.IMovieFinder"/> implementation.
|
||||
/// </returns>
|
||||
public IList FindAll()
|
||||
{
|
||||
return new ArrayList (_list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialises the in-mememory list of stored movies.
|
||||
/// </summary>
|
||||
private void InitList ()
|
||||
{
|
||||
_list.Add (new Movie ("La vita e bella", "Roberto Benigni"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
Blue Velvet:David Lynch
|
||||
Magnolia:Paul T Anderson
|
||||
Cabin Fever:Eli Roth
|
||||
In The Company Of Men:Neil Labute
|
||||
Naked:Mike Leigh
|
||||
La vita e bella:Roberto Benigni
|
||||
La vita e bella 2:Roberto Benigni
|
||||
@@ -0,0 +1,142 @@
|
||||
<VisualStudioProject>
|
||||
<CSHARP
|
||||
ProjectType = "Local"
|
||||
ProductVersion = "7.10.3077"
|
||||
SchemaVersion = "2.0"
|
||||
ProjectGuid = "{C261D9ED-85C3-4B35-BE48-7156F5B17430}"
|
||||
>
|
||||
<Build>
|
||||
<Settings
|
||||
ApplicationIcon = ""
|
||||
AssemblyKeyContainerName = ""
|
||||
AssemblyName = "Spring.IocQuickStart.MovieFinder"
|
||||
AssemblyOriginatorKeyFile = ""
|
||||
DefaultClientScript = "JScript"
|
||||
DefaultHTMLPageLayout = "Grid"
|
||||
DefaultTargetSchema = "IE50"
|
||||
DelaySign = "false"
|
||||
OutputType = "Exe"
|
||||
PreBuildEvent = ""
|
||||
PostBuildEvent = 'echo "Copying movies.txt file for MovieFinder"
copy "$(ProjectDir)MovieFinder\movies.txt" "$(TargetDir)" /y '
|
||||
RootNamespace = "Spring.IocQuickStart"
|
||||
RunPostBuildEvent = "OnOutputUpdated"
|
||||
StartupObject = "Spring.IocQuickStart.MovieFinder.Program"
|
||||
>
|
||||
<Config
|
||||
Name = "Debug"
|
||||
AllowUnsafeBlocks = "false"
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "DEBUG;TRACE"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "true"
|
||||
FileAlignment = "4096"
|
||||
IncrementalBuild = "false"
|
||||
NoStdLib = "false"
|
||||
NoWarn = ""
|
||||
Optimize = "false"
|
||||
OutputPath = "bin\Debug\"
|
||||
RegisterForComInterop = "false"
|
||||
RemoveIntegerChecks = "false"
|
||||
TreatWarningsAsErrors = "false"
|
||||
WarningLevel = "4"
|
||||
/>
|
||||
<Config
|
||||
Name = "Release"
|
||||
AllowUnsafeBlocks = "false"
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "TRACE"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "false"
|
||||
FileAlignment = "4096"
|
||||
IncrementalBuild = "false"
|
||||
NoStdLib = "false"
|
||||
NoWarn = ""
|
||||
Optimize = "true"
|
||||
OutputPath = "bin\Release\"
|
||||
RegisterForComInterop = "false"
|
||||
RemoveIntegerChecks = "false"
|
||||
TreatWarningsAsErrors = "false"
|
||||
WarningLevel = "4"
|
||||
/>
|
||||
</Settings>
|
||||
<References>
|
||||
<Reference
|
||||
Name = "System"
|
||||
AssemblyName = "System"
|
||||
HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Spring.Core"
|
||||
AssemblyName = "Spring.Core"
|
||||
HintPath = "..\..\..\..\bin\net\1.1\debug\Spring.Core.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Common.Logging"
|
||||
AssemblyName = "Common.Logging"
|
||||
HintPath = "..\..\..\..\bin\net\1.1\debug\Common.Logging.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "log4net"
|
||||
AssemblyName = "log4net"
|
||||
HintPath = "..\lib\net\1.1\log4net.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Common.Logging.Log4Net"
|
||||
AssemblyName = "Common.Logging.Log4Net"
|
||||
HintPath = "..\lib\net\1.1\Common.Logging.Log4Net.dll"
|
||||
/>
|
||||
</References>
|
||||
</Build>
|
||||
<Files>
|
||||
<Include>
|
||||
<File
|
||||
RelPath = "App.config"
|
||||
BuildAction = "None"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MovieFinder\AppContext.xml"
|
||||
BuildAction = "EmbeddedResource"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MovieFinder\ColonDelimitedMovieFinder.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MovieFinder\IMovieFinder.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MovieFinder\Movie.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MovieFinder\MovieLister.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MovieFinder\movies.txt"
|
||||
BuildAction = "Content"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MovieFinder\Program.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MovieFinder\SimpleMovieFinder.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
</Include>
|
||||
</Files>
|
||||
</CSHARP>
|
||||
</VisualStudioProject>
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectType>Local</ProjectType>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C261D9ED-85C3-4B35-BE48-7156F5B17430}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ApplicationIcon>
|
||||
</ApplicationIcon>
|
||||
<AssemblyKeyContainerName>
|
||||
</AssemblyKeyContainerName>
|
||||
<AssemblyName>Spring.IocQuickStart.MovieFinder</AssemblyName>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
<DefaultClientScript>JScript</DefaultClientScript>
|
||||
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
|
||||
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
||||
<DelaySign>false</DelaySign>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Spring.IocQuickStart</RootNamespace>
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
<StartupObject>Spring.IocQuickStart.MovieFinder.Program</StartupObject>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
<Optimize>false</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn>
|
||||
</NoWarn>
|
||||
<Optimize>true</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>none</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Common.Logging, Version=2.1.0.0, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\bin\net\2.0\debug\Common.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Common.Logging.Log4Net, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\lib\net\2.0\Common.Logging.Log4Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\lib\net\2.0\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Spring.Core, Version=1.1.0.2, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\bin\net\2.0\debug\Spring.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="MovieFinder\AppContext.xml" />
|
||||
<EmbeddedResource Include="MovieFinder\AppContextContribution.xml" />
|
||||
<Content Include="MovieFinder\movies.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MovieFinder\ColonDelimitedMovieFinder.cs" />
|
||||
<Compile Include="MovieFinder\IMovieFinder.cs" />
|
||||
<Compile Include="MovieFinder\Movie.cs" />
|
||||
<Compile Include="MovieFinder\Program.cs" />
|
||||
<Compile Include="MovieFinder\MovieLister.cs" />
|
||||
<Compile Include="MovieFinder\SimpleMovieFinder.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>echo "Copying movies.txt file for MovieFinder"
|
||||
copy "$(ProjectDir)MovieFinder\movies.txt" "$(TargetDir)" /y </PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user