How to use StructureMap
This article mainly shows you "how to use StructureMap", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use StructureMap" this article.
StructureMap is a very old IoC/DI container that has been supported since 2004. NET 1.1.
An implementation of the business interface public interface IDispatchService {} public interface ICourier {} public interface IPaymentGateway {} public interface IPaymentMerchant {} / / using the example / /: IDispatchService {private ICourier _ courier; public DispacthService (ICourier courier) {_ courier = courier } public override string ToString () {return _ courier.ToString ();}} public class FedExCourier: ICourier {} public class StreamLinePaymentMerchant: IPaymentMerchant {} public class PaymentGateway: IPaymentGateway {private IPaymentMerchant _ paymentMerchant; public PaymentGateway (IPaymentMerchant paymentMerchant) {_ paymentMerchant = paymentMerchant } public override string ToString () {return _ paymentMerchant.ToString ();} / / public class OrderService {private IPaymentGateway _ paymentGateway; private IDispatchService _ dispacthService; public OrderService (IPaymentGateway paymentGateway, IDispatchService dispacthService) {_ paymentGateway = paymentGateway; _ dispacthService = dispacthService } public override string ToString () {return string.Format ("IPaymentGateway: {0} IDispatchService: {1}", _ paymentGateway.ToString (), _ dispacthService.ToString ());}} / / configure dependency public class BootStrapper {public static void ConfigureStructureMap () {ObjectFactory.Initialize (x = > x.AddRegistry ()) } public class ModelRegistry: Registry {public ModelRegistry () {For () .Use ();}} class Program {static void Main (string [] args) {BootStrapper.ConfigureStructureMap () / / enable configuration OrderService orderService = ObjectFactory.GetInstance (); Console.WriteLine (orderService.ToString ()); IPaymentGateway paymentGateway= ObjectFactory.GetInstance (); Console.WriteLine (paymentGateway); Console.ReadKey ();}} these are all the contents of the article "how to use StructureMap". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!