Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use StructureMap

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report