Skip to content

Latest commit

 

History

History
95 lines (76 loc) · 2.13 KB

README.md

File metadata and controls

95 lines (76 loc) · 2.13 KB

Icon Sprout IoC

Build status License Stories in Ready

A down-to-earth IoC container implementation written in C#.

Usage

namespace MyNamespace
{
	[Component]
	public class MyComponent
	{
		[Inject]
		MyOtherComponent OtherComponent
		{
			set;
			get;
		}

		public void DoStuff()
		{
			...
		}

		[OnStart]
		void OnStart()
		{
			...
		}

		[OnEnd]
		void OnEnd()
		{
			...
		}
	}

	[Component]
	public class MyOtherComponent
	{
		...
	}
}

...

class MyMain
{
	static void Main(string[] args)
	{
		// Create context instance
		Context context = new Context();

		// Register application namespace and start
		context.Scan("MyNamespace").Start();

		// Register shutdown hook
		AppDomain.CurrentDomain.ProcessExit += (s, e) => context.Stop();

		// Get Context scoped components and interact with them
		MyComponent component = context.GetComponent<MyComponent>();
		component.DoStuff();

		// Wait until Context stops
		while (context.State != ContextState.Stopped)
		{
			Thread.Sleep(1000);
		}
	}
}

Bugs and Feedback

For bugs, questions and discussions please use the GitHub Issues.

LICENSE

Copyright 2015 ArenaNet, LLC.

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.