本文整理汇总了C#中IBinder.Bind方法的典型用法代码示例。如果您正苦于以下问题:C# IBinder.Bind方法的具体用法?C# IBinder.Bind怎么用?C# IBinder.Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBinder
的用法示例。
在下文中一共展示了IBinder.Bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindAsync
public override async Task BindAsync(IBinder binder, Stream stream, IReadOnlyDictionary<string, string> bindingData)
{
string boundQueueName = QueueName;
if (bindingData != null)
{
boundQueueName = _queueNameBindingTemplate.Bind(bindingData);
}
if (FileAccess == FileAccess.Write)
{
Stream queueStream = binder.Bind<Stream>(new QueueAttribute(boundQueueName));
await queueStream.CopyToAsync(stream);
}
else
{
IAsyncCollector<byte[]> collector = binder.Bind<IAsyncCollector<byte[]>>(new QueueAttribute(boundQueueName));
byte[] bytes;
using (MemoryStream ms = new MemoryStream())
{
stream.CopyTo(ms);
bytes = ms.ToArray();
}
await collector.AddAsync(bytes);
}
}
示例2: Init
public void Init()
{
this.binder = new Binder();
//Binds some objects to use on tests.
binder.Bind<IMockInterface>().To<MockIClassWithAttributes>();
binder.Bind(typeof(MockClassWithDependencies)).ToSelf();
}
示例3: QueueToBlob
/// <summary>
/// Reads a message from the "orders" queue and writes a blob in the "orders" container
/// </summary>
public static void QueueToBlob(
[QueueTrigger("orders")] string orders,
IBinder binder)
{
TextWriter writer = binder.Bind<TextWriter>(new BlobAttribute("orders/" + orders));
writer.Write("Completed");
}
示例4: ProcessQueueMessage
// This function will get triggered/executed when a new message is written
// on an Azure Queue called queue.
public static void ProcessQueueMessage([QueueTrigger("afro")] String message, TextWriter log, IBinder binder, Int32 dequeueCount)
{
log.WriteLine("este es el intento numero{0}", dequeueCount);
if (dequeueCount <= 5)
{
binder.Bind<QueueAttribute>(new QueueAttribute("afro-poison"));
}
throw new Exception("throw perra");
}
示例5: Init
public void Init()
{
this.injector = new InjectionContainer();
this.binder = this.injector as IBinder;
//Binds some objects to use on tests.
binder.Bind<IMockInterface>().To<MockIClassWithAttributes>();
binder.Bind<MockIClassWithoutAttributes>().ToSingleton().As("singleton");
binder.Bind<MockIClass>().ToSingleton();
this.containerIdentifierTests = new InjectionContainer();
var mockClass1 = new MockIClass() { property1 = "MockClass1" };
var mockClass2 = new MockIClassWithoutAttributes() { property1 = "MockClass2" };
var mockClass3 = new MockIClassWithAttributes() { property1 = "MockClass3" };
this.containerIdentifierTests.Bind<MockIClass>().To(mockClass1).As(TestIdentifier.MockClass);
this.containerIdentifierTests.Bind<MockIClassWithoutAttributes>().To(mockClass2).As(TestIdentifier.MockClass);
this.containerIdentifierTests.Bind<MockIClassWithAttributes>().To(mockClass3).As(TestIdentifier.MockClass);
this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass1).As(TestIdentifier.MockClass1);
this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass2).As(TestIdentifier.MockClass2);
this.containerIdentifierTests.Bind<IMockInterface>().To(mockClass3).As(TestIdentifier.MockClass3);
this.containerIdentifierTests.Bind<IMockInterface>().To<MockIClass>().As(TestIdentifier.MockClassSingle);
}
示例6: BackupFile
public static void BackupFile(
string fileContent,
string fileName,
IBinder binder,
TextWriter log)
{
log.WriteLine("Backing up file in Azure Storage: " + fileName);
// Use IBinder because property binding doesn't work without a trigger attribute
// if it would work, the code would be much simpler
TextWriter backupFile = binder.Bind<TextWriter>(new BlobAttribute("backup/" + fileName));
backupFile.Write(fileContent);
}
示例7: RecordTime
public static void RecordTime(IBinder binder, TextWriter logger)
{
var start = $"{DateTime.UtcNow:yyyyMMdd-HHmmss}";
var blobAttribute = new BlobAttribute($"output/{start}");
var blob = binder.Bind<CloudBlockBlob>(blobAttribute);
blob.UploadText(start);
logger.WriteLine(start);
//RecordTimeAndSleep(start, blob, logger);
RecordTimes(start, blob, logger);
}
示例8: CreateShuffle
/// <summary>
/// Waits for message from the queue and creates shuffles
/// </summary>
/// <param name="shufflerequests">The message received from queue</param>
public static void CreateShuffle(
[QueueInput] ShuffleRequestMessage shufflerequests,
IBinder binder)
{
string shuffleId = shufflerequests.ShuffleId;
ImageProcessingJobs processor = new ImageProcessingJobs();
string shuffle = processor.CreateShuffle(shuffleId);
Stream shuffleBlob = binder.Bind<Stream>(new BlobOutputAttribute("shuffle" + shuffleId + @"/shuffle.jpg"));
using (Stream localShuffle = File.OpenRead(shuffle))
{
localShuffle.CopyTo(shuffleBlob);
}
}
示例9: ScanAndRegisterHandlers
void ScanAndRegisterHandlers(IBinder binder, IScanner scanner)
{
var handlerTups = scanner.ScanTypes(typeof(Registrar).Assembly)
.Where(t => !t.IsAbstract)
.Select(t => new {
ImplType = t,
IntType = t.GetInterfaces()
.SingleOrDefault(i => i.IsGenericType
&& i.GetGenericTypeDefinition() == typeof(IQueryHandler<,>))
})
.Where(tup => tup.IntType != null);
foreach(var tup in handlerTups) {
binder.Bind(tup.IntType, tup.ImplType);
}
}
示例10: CreateShuffle
/// <summary>
/// Waits for message from the queue and creates shuffles
/// </summary>
/// <param name="shufflerequest">The message received from queue</param>
public static void CreateShuffle(
[QueueTrigger("shufflerequests")] ShuffleRequestMessage shufflerequest,
IBinder binder)
{
string shuffleId = shufflerequest.ShuffleId;
ImageProcessingJobs processor = new ImageProcessingJobs();
string shuffle = processor.CreateShuffle(shuffleId);
BlobAttribute attribute = new BlobAttribute("shuffle" + shuffleId + @"/shuffle.jpg", FileAccess.Write);
Stream shuffleBlob = binder.Bind<Stream>(attribute);
using (Stream localShuffle = File.OpenRead(shuffle))
{
localShuffle.CopyTo(shuffleBlob);
}
}
示例11: BindAsync
public override async Task BindAsync(IBinder binder, Stream stream, IReadOnlyDictionary<string, string> bindingData)
{
string boundBlobPath = Path;
if (bindingData != null)
{
boundBlobPath = _pathBindingTemplate.Bind(bindingData);
}
Stream blobStream = binder.Bind<Stream>(new BlobAttribute(boundBlobPath, FileAccess));
if (FileAccess == FileAccess.Write)
{
await stream.CopyToAsync(blobStream);
}
else
{
await blobStream.CopyToAsync(stream);
}
}
示例12: Bind
public void Bind(IBinder binder)
{
Mock<IUnitOfWork> mock = new Mock<IUnitOfWork>();
mock.Setup(m => m.Products.GetAll()).Returns(new List<Product>
{
new Product {ProductID=1,Name = "Table", Price = 25, Category="Kitchen"},
new Product {ProductID=2,Name = "Ball", Price = 179,Category = "Outside"},
new Product {ProductID=3,Name = "Oven", Price = 95, Category="Kitchen"},
new Product {ProductID=4,Name = "KeyBoard", Price = 10,Category = "Office"},
new Product {ProductID=5,Name = "Phone", Price = 20,Category = "Office"},
new Product {ProductID=6,Name = "Mouse", Price = 45,Category = "Office"},
new Product {ProductID=7,Name = "TV", Price = 34, Category = "Office"},
new Product {ProductID=8,Name = "Glass", Price = 47,Category = "Kitchen"},
new Product {ProductID=9,Name = "Plate", Price = 88, Category="Kitchen"},
new Product {ProductID=10,Name = "Fork", Price = 44, Category="Kitchen"},
new Product {ProductID=11,Name = "Knife", Price = 66, Category ="Kitchen"}
}.AsQueryable());
//binder.BindToConstant<IUnitOfWork, IUnitOfWork>(mock.Object);
binder.Bind<IUnitOfWork, StefanStoreUow>();
}
示例13: BlobIBinder
/// <summary>
/// Same as "BlobNameFromQueueMessage" but using IBinder
/// </summary>
public static void BlobIBinder(
[QueueTrigger("persons")] Person persons,
IBinder binder)
{
TextWriter writer = binder.Bind<TextWriter>(new BlobAttribute("persons/" + persons.Name + "BlobIBinder"));
writer.Write("Hello " + persons.Name);
}
示例14: Register
public void Register(IBinder x, IScanner scanner)
{
x.Bind<HttpContext>(_ => HttpContext.Current);
x.Bind<HttpContextBase>(_ => new HttpContextWrapper(HttpContext.Current));
x.Bind(c => c.Resolve<HttpContext>().Request);
x.Bind(c => c.Resolve<HttpContext>().Response);
x.Bind(c => c.Resolve<HttpContext>().Server);
x.Bind(c => c.Resolve<HttpContext>().Session);
x.BindSingleton<ICache>(_ => new BrigitaCache(MemoryCache.Default));
x.Bind<ICacheManager, MemoryCacheManager>();
//x.Register<IRoutePublisher, RoutePublisher>();
x.Bind<IEventPublisher, EventPublisher>();
x.Bind<ISubscriptionService, SubscriptionService>();
x.Bind<IGenericAttributeService, GenericAttributeService>();
x.Bind<IPluginFinder, BrigitaPluginFinder>();
x.Bind<ILogger, NullLogger>();
x.BindGeneric(typeof(IRepo<>), typeof(Repo<>));
x.Bind<ILinkProvider, LinkProvider>();
x.Bind<IMediator, Mediator>();
x.Bind<IPicSource, PicSource>();
x.Bind<IPictureService, PictureService>();
x.Bind<ILocaleContext, LocaleContext>();
x.Bind<ILocaleCodeProvider, LocaleCodeProvider>();
x.BindGeneric(typeof(ILocalizer<>), typeof(Localizer<>));
x.BindGeneric(typeof(IStringLocalizer<>), typeof(StringLocalizer<>));
x.BindGeneric(typeof(ICurrencyLocalizer<>), typeof(CurrencyLocalizer<>));
x.Bind<IWorkContext, BrigitaWorkContext>();
x.Bind<IPageHelper, PageHelper>();
x.Bind<ILinkHelper, LinkHelper>();
//!!!!!!!! JUST FOR TESTING... !!!!!!!!!
x.Bind(new StoreInformationSettings());
x.Bind(new TaxSettings());
x.Bind(new CurrencySettings());
x.Bind(new LocalizationSettings());
x.Bind(new CustomerSettings());
x.Bind(new CommonSettings());
x.Bind(new CatalogSettings());
x.Bind(new SeoSettings());
x.Bind(new MediaSettings());
x.Bind<ISettingService, SettingService>();
x.Bind<IUserAgentHelper, UserAgentHelper>();
x.Bind<IWebHelper, WebHelper>();
/*x.Bind<IWorkContext, WebWorkContext>();*/
x.Bind<IStoreContext, WebStoreContext>();
x.Bind<ICategories, BrigitaCategories>();
x.Bind<IScopedCategories, ScopedCategories>();
x.Bind<IProducts, BrigitaProducts>();
x.Bind<ICustomerService, CustomerService>();
x.Bind<IVendorService, VendorService>();
x.Bind<IStoreService, BrigitaStores>();
x.Bind<IAuthenticationService, FormsAuthenticationService>();
x.Bind<ILanguageService, LanguageService>();
x.Bind<ICurrencyService, CurrencyService>();
x.Bind<IStoreMappingService, StoreMappingService>();
x.Bind<IPageHeadBuilder, PageHeadBuilder>();
//data layer
var dataSettingsManager = new DataSettingsManager();
var dataProviderSettings = dataSettingsManager.LoadSettings();
x.Bind<DataSettings>(c => dataSettingsManager.LoadSettings());
x.BindTransient<BaseDataProviderManager, EfDataProviderManager>();
x.BindTransient<IDataProvider>(c => c.Resolve<BaseDataProviderManager>().LoadDataProvider());
if(dataProviderSettings != null && dataProviderSettings.IsValid()) {
var efDataProviderManager = new EfDataProviderManager(dataSettingsManager.LoadSettings());
var dataProvider = efDataProviderManager.LoadDataProvider();
dataProvider.InitConnectionFactory();
x.Bind<IDbContext>(c => new NopObjectContext(dataProviderSettings.DataConnectionString, false, false));
}
//.........这里部分代码省略.........
示例15: Bind
public void Bind(IBinder binder)
{
binder.Bind<IProductService,ProductService>();
binder.Bind<INavigationService, NavigationService>();
binder.Bind<ICartService, CartService>();
}